Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if screen is unlocked

Tags:

android

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.

like image 675
Jakob Avatar asked Nov 28 '22 13:11

Jakob


1 Answers

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

like image 142
JanBo Avatar answered Jan 14 '23 21:01

JanBo