Share via


KeyguardManager.IsKeyguardLocked Property

Definition

Returns whether the lock screen (also known as Keyguard) is showing.

public virtual bool IsKeyguardLocked { [Android.Runtime.Register("isKeyguardLocked", "()Z", "GetIsKeyguardLockedHandler")] get; }
[<get: Android.Runtime.Register("isKeyguardLocked", "()Z", "GetIsKeyguardLockedHandler")>]
member this.IsKeyguardLocked : bool

Property Value

true if the lock screen is showing

Attributes

Remarks

Returns whether the lock screen (also known as Keyguard) is showing.

Specifically, this returns true in the following cases: <ul> <li>The lock screen is showing in the foreground.</li> <li>The lock screen is showing, but it is occluded by an activity that is showing on top of it. A common example is the phone app receiving a call or making an emergency call.</li> <li>The lock screen was showing but is temporarily disabled as a result of lock task mode or an app using the deprecated KeyguardLock API.</li> </ul>

"Showing" refers to a logical state of the UI, regardless of whether the screen happens to be on. When the power button is pressed on an unlocked device, the lock screen starts "showing" immediately when the screen turns off.

This method does not distinguish a lock screen that is requiring authentication (e.g. with PIN, pattern, password, or biometric) from a lock screen that is trivially dismissible (e.g. with swipe). It also does not distinguish a lock screen requesting a SIM card PIN from a normal device lock screen. Finally, it always returns the global lock screen state and does not consider the Context's user specifically.

Note that isKeyguardLocked() is confusingly named and probably should be called isKeyguardShowing(). On many devices, the lock screen displays an unlocked padlock icon when it is trivially dismissible. As mentioned above, isKeyguardLocked() actually returns true in this case, not false as might be expected. #isDeviceLocked() is an alternative API that has slightly different semantics.

Java documentation for android.app.KeyguardManager.isKeyguardLocked().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to