Check if the screen is unlocked android service

Asked

Viewed 60 times

0

I’m developing an app that has a service of AlarmManager who subsequently calls a Service. It turns out that when you start the Service I want to check if the phone is in use, IE, with the screen access and unlocked, because if it displays a notification, otherwise starts a Activity. Is there any method or class to check this and give me a feedback?

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: https://stackoverflow.com/a/8668648/194717

  • It worked perfectly, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.