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.
if(isKeyboardLocked(context)){
// screen blocked
}
private boolean isKeyboardLocked(Context context) {
KeyguardManager myKM = (KeyguardManager) context
.getSystemService(Context.KEYGUARD_SERVICE);
return myKM.inKeyguardRestrictedInputMode();
}