How to unlock the screen programmatically on the root device?

I want to turn off the screen locker (even if it is locked) or change it to some simple lock, for example, swipe the screen to open in my application when the laptop is close, so I don’t have to write my 12-digit digits PIN every time when I want to read notifications.

I know how to detect the presence of a laptop on one network (it is unsafe, but for me there is enough security for the unknown), but I could not find anything else, except that it is impossible on unloaded devices. There is a system application that takes care of setting the lock screen, so it should be possible.

I am working on Android 4.4.

+4
source share
1 answer

This should work:

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
        | PowerManager.ACQUIRE_CAUSES_WAKEUP
        | PowerManager.ON_AFTER_RELEASE, "INFO");
wl.acquire();

KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock kl = km.newKeyguardLock("name");
kl.disableKeyguard();
+1
source

All Articles