AOSP Android Pie Check if Keyguard is showed

271 views Asked by At

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)

1

There are 1 answers

2
Sana On

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. :)