How can I check if the screen is unlocked (E.i. Turned on and not on lockscreen)?
PS. I'm not looking for the unlock event, which I know can be retrieved with an AdminDeviceReceiver, but I'm looking for an executable code that will return a boolean telling me whether or not the screen is unlocked.
Try with this:
KeyguardManager myKM = (KeyguardManager) сontext.getSystemService(Context.KEYGUARD_SERVICE);
if( myKM.inKeyguardRestrictedInputMode() ) {
// it is locked
} else {
//it is not locked
}
Taken from: Detecting when screen is locked
Also same answer : How to tell if user is on lock screen from service
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With