Check if the screen is unlocked service android

0

I'm developing an application that has a AlarmManager service that later calls a Service . It happens that when I start Service I want to check if the phone is in use, that is, with the screen accesses and unlocked, because if a notification is displayed, otherwise it starts a Activity . Is there any method or class to check this out and give me a feedback?

    
asked by anonymous 19.09.2014 / 21:37

1 answer

1

Try the KeyguardManager:

KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if( myKM.inKeyguardRestrictedInputMode()) {
 //it is locked
} else {
 //it is not locked
}

Source: link

    
19.09.2014 / 23:20