Is there a way to detect if the keyguard is displayed on the screen? I know there is the method isKeyguardLocked()
but it is true for Keyguard Locked (Even if the keyguard is not displayed on the screen)
Asked
Active
Viewed 216 times
0

Bazouk55555
- 557
- 6
- 24
1 Answers
0
Instead of using isKeyguardLocked() , you can use isKeyguardSecure().
Or
use the method like in the following for if the keyLocked screen is displayed or not,
public static boolean isKeyGuardDisplayed(Context context) {
KeyguardManager manager = (KeyguardManager) context.getSystemService(context.KEYGUARD_SERVICE);
return manager.inKeyguardRestrictedInputMode();
}
Or,
public static boolean isKeyGuardDisplayed(Context context) {
KeyguardManager manager = (KeyguardManager) context.getSystemService(context.KEYGUARD_SERVICE);
return manager.isDeviceLocked();
}
Hope this answer will help you. :)

Sana
- 456
- 3
- 9
-
I tried but unfortunately, for Android Pie, the method inKeyguardRestrictedInputMode() is deprecated :( – Bazouk55555 Jul 27 '20 at 12:18
-
Yes I know.Then try the same using isDeviceLocked()Also I have edited my answer – Sana Jul 27 '20 at 12:21