1

I am using the below code to unlock my screen phone. It worked well to unlock my phone in swipe mode(Swipe up to unlock). However, by using the method, it remove the swipe mode in my phone It means I cannot lock my phone using swipe mode again (press the power button). I think the issue is the line kl.disableKeyguard();. I am looking for a best method for lock and unlock phone (Android 5.1, 6.0) using programming. Could you suggest to me the way for my task? I found some related work but it is so old. I expect these methods that uses Intent.

How to Lock/Unlock screen programmatically?

KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
            final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("MyKeyguardLock");
            kl.disableKeyguard();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
                | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
        wakeLock.acquire();
Community
  • 1
  • 1
KimHee
  • 728
  • 2
  • 12
  • 22

0 Answers0