0

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)

Bazouk55555
  • 557
  • 6
  • 24

1 Answers1

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