Android APIs
public class

KeyguardManager

extends Object
java.lang.Object
   ↳ android.app.KeyguardManager

Class Overview

Class that can be used to lock and unlock the keyboard. Get an instance of this class by calling getSystemService(java.lang.String) with argument KEYGUARD_SERVICE. The actual class to control the keyboard locking is KeyguardManager.KeyguardLock.

Summary

Nested Classes
class KeyguardManager.KeyguardLock This class was deprecated in API level 13. Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Handle returned by newKeyguardLock(String) that allows you to disable / reenable the keyguard.  
interface KeyguardManager.OnKeyguardExitResult Callback passed to exitKeyguardSecurely(KeyguardManager.OnKeyguardExitResult) to notify caller of result. 
Public Methods
Intent createConfirmDeviceCredentialIntent(CharSequence title, CharSequence description)
Get an intent to prompt the user to confirm credentials (pin, pattern or password) for the current user of the device.
void exitKeyguardSecurely(KeyguardManager.OnKeyguardExitResult callback)
This method was deprecated in API level 13. Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Exit the keyguard securely. The use case for this api is that, after disabling the keyguard, your app, which was granted permission to disable the keyguard and show a limited amount of information deemed safe without the user getting past the keyguard, needs to navigate to something that is not safe to view without getting past the keyguard. This will, if the keyguard is secure, bring up the unlock screen of the keyguard.

This method requires the caller to hold the permission DISABLE_KEYGUARD.

boolean inKeyguardRestrictedInputMode()
If keyguard screen is showing or in restricted key input mode (i.e.
boolean isDeviceLocked()
Returns whether the device is currently locked and requires a PIN, pattern or password to unlock.
boolean isKeyguardLocked()
Return whether the keyguard is currently locked.
boolean isKeyguardSecure()
Return whether the keyguard requires a password to unlock.
KeyguardManager.KeyguardLock newKeyguardLock(String tag)
This method was deprecated in API level 13. Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Enables you to lock or unlock the keyboard. Get an instance of this class by calling Context.getSystemService(). This class is wrapped by KeyguardManager.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public Intent createConfirmDeviceCredentialIntent (CharSequence title, CharSequence description)

Added in API level 21

Get an intent to prompt the user to confirm credentials (pin, pattern or password) for the current user of the device. The caller is expected to launch this activity using startActivityForResult(Intent, int) and check for RESULT_OK if the user successfully completes the challenge.

Returns
  • the intent for launching the activity or null if no password is required.

public void exitKeyguardSecurely (KeyguardManager.OnKeyguardExitResult callback)

Added in API level 1

This method was deprecated in API level 13.
Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Exit the keyguard securely. The use case for this api is that, after disabling the keyguard, your app, which was granted permission to disable the keyguard and show a limited amount of information deemed safe without the user getting past the keyguard, needs to navigate to something that is not safe to view without getting past the keyguard. This will, if the keyguard is secure, bring up the unlock screen of the keyguard.

This method requires the caller to hold the permission DISABLE_KEYGUARD.

Parameters
callback Let's you know whether the operation was succesful and it is safe to launch anything that would normally be considered safe once the user has gotten past the keyguard.

public boolean inKeyguardRestrictedInputMode ()

Added in API level 1

If keyguard screen is showing or in restricted key input mode (i.e. in keyguard password emergency screen). When in such mode, certain keys, such as the Home key and the right soft keys, don't work.

Returns
  • true if in keyguard restricted input mode.
See Also
  • inKeyguardRestrictedKeyInputMode()

public boolean isDeviceLocked ()

Returns whether the device is currently locked and requires a PIN, pattern or password to unlock.

Returns
  • true if unlocking the device currently requires a PIN, pattern or password.

public boolean isKeyguardLocked ()

Added in API level 16

Return whether the keyguard is currently locked.

Returns
  • true if keyguard is locked.

public boolean isKeyguardSecure ()

Added in API level 16

Return whether the keyguard requires a password to unlock.

Returns
  • true if keyguard is secure.

public KeyguardManager.KeyguardLock newKeyguardLock (String tag)

Added in API level 1

This method was deprecated in API level 13.
Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Enables you to lock or unlock the keyboard. Get an instance of this class by calling Context.getSystemService(). This class is wrapped by KeyguardManager.

Parameters
tag A tag that informally identifies who you are (for debugging who is disabling he keyguard).
Returns