Question

Does anybody know easiest way to determine, when device's screen is blocked (not switched off)?

It is necessary for the case, when notifications may contain private information, but they shown on blocked screen. I want not to show it.

Was it helpful?

Solution

if(isKeyboardLocked(context)){
// screen blocked
}

private boolean isKeyboardLocked(Context context) {
            KeyguardManager myKM = (KeyguardManager) context
                    .getSystemService(Context.KEYGUARD_SERVICE);
            return myKM.inKeyguardRestrictedInputMode();
        }

OTHER TIPS

This is the way to check it

KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if( myKM.inKeyguardRestrictedInputMode()) {
    //it is locked
} else {
 //it is not locked
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top