KeyguardManager | Android Developers
source link: https://developer.android.com/reference/android/app/KeyguardManager
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
KeyguardManager | Android Developers
- Android API Reference
- Overview
- Android Platform
- Packages
- API level
- Class Index
- Package Index
- android
- android.accessibilityservice
- android.accounts
- android.adservices
- android.animation
- android.annotation
- android.app.admin
- android.app.appsearch
- android.app.appsearch.exceptions
- android.app.appsearch.observer
- android.app.assist
- android.app.backup
- android.app.blob
- android.app.job
- android.app.people
- android.app.role
- android.app.slice
- android.app.usage
- android.appwidget
- android.bluetooth
- android.bluetooth.le
- android.companion
- android.content
- android.content.pm
- android.content.pm.verify.domain
- android.content.res
- android.content.res.loader
- android.database
- android.database.sqlite
- android.drm
- android.gesture
- android.graphics
- android.graphics.drawable
- android.graphics.drawable.shapes
- android.graphics.fonts
- android.graphics.pdf
- android.graphics.text
- android.hardware
- android.hardware.biometrics
- android.hardware.camera2
- android.hardware.camera2.params
- android.hardware.display
- android.hardware.fingerprint
- android.hardware.input
- android.hardware.lights
- android.hardware.usb
- android.icu.lang
- android.icu.math
- android.icu.number
- android.icu.text
- android.icu.util
- android.inputmethodservice
- android.location
- android.location.provider
- android.media
- android.media.audiofx
- android.media.browse
- android.media.effect
- android.media.metrics
- android.media.midi
- android.media.projection
- android.media.session
- android.media.tv
- android.media.tv.interactive
- android.mtp
- android.net
- android.net.eap
- android.net.http
- android.net.ipsec.ike
- android.net.ipsec.ike.exceptions
- android.net.nsd
- android.net.rtp
- android.net.sip
- android.net.ssl
- android.net.vcn
- android.net.wifi
- android.net.wifi.aware
- android.net.wifi.hotspot2
- android.net.wifi.hotspot2.omadm
- android.net.wifi.hotspot2.pps
- android.net.wifi.p2p
- android.net.wifi.p2p.nsd
- android.net.wifi.rtt
- android.nfc
- android.nfc.cardemulation
- android.nfc.tech
- android.opengl
- android.os
- android.os.ext
- android.os.health
- android.os.storage
- android.os.strictmode
- android.os.vibrator
- android.preference
- android.print
- android.print.pdf
- android.printservice
- android.provider
- android.renderscript
- android.sax
- android.se.omapi
- android.security
- android.security.identity
- android.security.keystore
- android.service.autofill
- android.service.carrier
- android.service.chooser
- android.service.controls
- android.service.controls.actions
- android.service.controls.templates
- android.service.dreams
- android.service.media
- android.service.notification
- android.service.quickaccesswallet
- android.service.quicksettings
- android.service.restrictions
- android.service.textservice
- android.service.voice
- android.service.vr
- android.service.wallpaper
- android.speech
- android.speech.tts
- android.system
- android.telecom
- android.telephony
- android.telephony.cdma
- android.telephony.data
- android.telephony.emergency
- android.telephony.euicc
- android.telephony.gsm
- android.telephony.ims
- android.telephony.ims.feature
- android.telephony.ims.stub
- android.telephony.mbms
- android.test
- android.test.mock
- android.test.suitebuilder
- android.test.suitebuilder.annotation
- android.text
- android.text.format
- android.text.method
- android.text.style
- android.text.util
- android.transition
- android.util
- android.util.proto
- android.view
- android.view.accessibility
- android.view.animation
- android.view.autofill
- android.view.contentcapture
- android.view.displayhash
- android.view.inputmethod
- android.view.inspector
- android.view.textclassifier
- android.view.textservice
- android.view.translation
- android.webkit
- android.widget
- android.widget.inline
- android.window
- dalvik.annotation
- dalvik.bytecode
- dalvik.system
- java.awt.font
- java.beans
- java.io
- java.lang
- java.lang.annotation
- java.lang.invoke
- java.lang.ref
- java.lang.reflect
- java.math
- java.net
- java.nio
- java.nio.channels
- java.nio.channels.spi
- java.nio.charset
- java.nio.charset.spi
- java.nio.file
- java.nio.file.attribute
- java.nio.file.spi
- java.security
- java.security.acl
- java.security.cert
- java.security.interfaces
- java.security.spec
- java.sql
- java.text
- java.time
- java.time.chrono
- java.time.format
- java.time.temporal
- java.time.zone
- java.util
- java.util.concurrent
- java.util.concurrent.atomic
- java.util.concurrent.locks
- java.util.function
- java.util.jar
- java.util.logging
- java.util.prefs
- java.util.regex
- java.util.stream
- java.util.zip
- javax.crypto
- javax.crypto.interfaces
- javax.crypto.spec
- javax.microedition.khronos.egl
- javax.microedition.khronos.opengles
- javax.net
- javax.net.ssl
- javax.security.auth
- javax.security.auth.callback
- javax.security.auth.login
- javax.security.auth.x500
- javax.security.cert
- javax.sql
- javax.xml
- javax.xml.datatype
- javax.xml.namespace
- javax.xml.parsers
- javax.xml.transform
- javax.xml.transform.dom
- javax.xml.transform.sax
- javax.xml.transform.stream
- javax.xml.validation
- javax.xml.xpath
- junit.framework
- junit.runner
- org.apache.http.conn
- org.apache.http.conn.scheme
- org.apache.http.conn.ssl
- org.apache.http.params
- org.json
- org.w3c.dom
- org.w3c.dom.ls
- org.xml.sax
- org.xml.sax.ext
- org.xml.sax.helpers
- org.xmlpull.v1
- org.xmlpull.v1.sax2
KeyguardManager
public
class
KeyguardManager
extends Object
java.lang.Object | |
↳ | android.app.KeyguardManager |
Class that can be used to lock and unlock the keyguard. The
actual class to control the keyguard locking is
KeyguardManager.KeyguardLock
.
Summary
Nested classes | |
---|---|
class |
KeyguardManager.KeyguardDismissCallback
Callback passed to
|
class |
KeyguardManager.KeyguardLock
This class was deprecated
in API level 15.
Use |
interface |
KeyguardManager.KeyguardLockedStateListener
Listener for keyguard locked state changes. |
interface |
KeyguardManager.OnKeyguardExitResult
This interface was deprecated
in API level 26.
Use |
Public methods | |
---|---|
void
|
addKeyguardLockedStateListener(Executor executor, KeyguardManager.KeyguardLockedStateListener listener)
Registers a listener to execute when the keyguard visibility changes. |
Intent
|
createConfirmDeviceCredentialIntent(CharSequence title, CharSequence description)
This method was deprecated in API level 29. see BiometricPrompt.Builder#setDeviceCredentialAllowed(boolean) |
void
|
exitKeyguardSecurely(KeyguardManager.OnKeyguardExitResult callback)
This method was deprecated
in API level 15.
Use |
boolean
|
inKeyguardRestrictedInputMode()
This method was deprecated
in API level 28.
Use |
boolean
|
isDeviceLocked()
Returns whether the device is currently locked and requires a PIN, pattern or password to unlock. |
boolean
|
isDeviceSecure()
Returns whether the device is secured with a PIN, pattern or password. |
boolean
|
isKeyguardLocked()
Return whether the keyguard is currently locked. |
boolean
|
isKeyguardSecure()
Return whether the keyguard is secured by a PIN, pattern or password or a SIM card is currently locked. |
KeyguardManager.KeyguardLock
|
newKeyguardLock(String tag)
This method was deprecated
in API level 15.
Use |
void
|
removeKeyguardLockedStateListener(KeyguardManager.KeyguardLockedStateListener listener)
Unregisters a listener that executes when the keyguard visibility changes. |
void
|
requestDismissKeyguard(Activity activity, KeyguardManager.KeyguardDismissCallback callback)
If the device is currently locked (see |
Inherited methods |
---|
From class
java.lang.Object
|
Public methods
addKeyguardLockedStateListener
public void addKeyguardLockedStateListener (Executor executor, KeyguardManager.KeyguardLockedStateListener listener)
Registers a listener to execute when the keyguard visibility changes.
Requires Manifest.permission.SUBSCRIBE_TO_KEYGUARD_LOCKED_STATE
Parameters | |
---|---|
executor |
Executor : This value cannot be null .
Callback and listener events are dispatched through this
Executor , providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor() .
To dispatch events through a shared thread pool, you can use
AsyncTask#THREAD_POOL_EXECUTOR . |
listener |
KeyguardManager.KeyguardLockedStateListener : The listener to add to receive keyguard visibility changes.
This value cannot be null . |
createConfirmDeviceCredentialIntent
public Intent createConfirmDeviceCredentialIntent (CharSequence title, CharSequence description)
This method was deprecated
in API level 29.
see BiometricPrompt.Builder#setDeviceCredentialAllowed(boolean)
Get an intent to prompt the user to confirm credentials (pin, pattern, password or biometrics
if enrolled) for the current user of the device. The caller is expected to launch this
activity using Activity.startActivityForResult(Intent, int)
and check for
Activity.RESULT_OK
if the user successfully completes the challenge.
Requires the PackageManager#FEATURE_SECURE_LOCK_SCREEN
feature which can be detected using PackageManager.hasSystemFeature(String)
.
Parameters | |
---|---|
title |
CharSequence |
description |
CharSequence |
Returns | |
---|---|
Intent |
the intent for launching the activity or null if no password is required. |
exitKeyguardSecurely
public void exitKeyguardSecurely (KeyguardManager.OnKeyguardExitResult callback)
This method was deprecated
in API level 15.
Use LayoutParams#FLAG_DISMISS_KEYGUARD
and/or LayoutParams#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.
Requires Manifest.permission.DISABLE_KEYGUARD
Parameters | |
---|---|
callback |
KeyguardManager.OnKeyguardExitResult : Lets you know whether the operation was successful and
it is safe to launch anything that would normally be considered safe
once the user has gotten past the keyguard. |
inKeyguardRestrictedInputMode
public boolean inKeyguardRestrictedInputMode ()
This method was deprecated
in API level 28.
Use isKeyguardLocked()
instead.
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 | |
---|---|
boolean |
true if in keyguard restricted input mode. |
isDeviceLocked
public boolean isDeviceLocked ()
Returns whether the device is currently locked and requires a PIN, pattern or password to unlock.
Returns | |
---|---|
boolean |
true if unlocking the device currently requires a PIN, pattern or
password. |
isDeviceSecure
public boolean isDeviceSecure ()
Returns whether the device is secured with a PIN, pattern or password.
See also isKeyguardSecure()
which treats SIM locked states as secure.
Returns | |
---|---|
boolean |
true if a PIN, pattern or password was set. |
isKeyguardLocked
public boolean isKeyguardLocked ()
Return whether the keyguard is currently locked.
Returns | |
---|---|
boolean |
true if the keyguard is locked. |
isKeyguardSecure
public boolean isKeyguardSecure ()
Return whether the keyguard is secured by a PIN, pattern or password or a SIM card is currently locked.
See also isDeviceSecure()
which ignores SIM locked states.
Returns | |
---|---|
boolean |
true if a PIN, pattern or password is set or a SIM card is locked. |
newKeyguardLock
public KeyguardManager.KeyguardLock newKeyguardLock (String tag)
This method was deprecated
in API level 15.
Use LayoutParams#FLAG_DISMISS_KEYGUARD
and/or LayoutParams#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 keyguard. Get an instance of this class by
calling Context.getSystemService()
.
This class is wrapped by KeyguardManager
.
Parameters | |
---|---|
tag |
String : A tag that informally identifies who you are (for debugging who
is disabling the keyguard). |
Returns | |
---|---|
KeyguardManager.KeyguardLock |
A KeyguardLock handle to use to disable and reenable the
keyguard. |
removeKeyguardLockedStateListener
public void removeKeyguardLockedStateListener (KeyguardManager.KeyguardLockedStateListener listener)
Unregisters a listener that executes when the keyguard visibility changes.
Requires Manifest.permission.SUBSCRIBE_TO_KEYGUARD_LOCKED_STATE
Parameters | |
---|---|
listener |
KeyguardManager.KeyguardLockedStateListener : This value cannot be null . |
requestDismissKeyguard
public void requestDismissKeyguard (Activity activity, KeyguardManager.KeyguardDismissCallback callback)
If the device is currently locked (see isKeyguardLocked()
, requests the Keyguard to
be dismissed.
If the Keyguard is not secure or the device is currently in a trusted state, calling this method will immediately dismiss the Keyguard without any user interaction.
If the Keyguard is secure and the device is not in a trusted state, this will bring up the UI so the user can enter their credentials.
If the value set for the Activity
attr R.attr.turnScreenOn
is true,
the screen will turn on when the keyguard is dismissed.
Parameters | |
---|---|
activity |
Activity : The activity requesting the dismissal. The activity must be either visible
by using LayoutParams#FLAG_SHOW_WHEN_LOCKED or must be in a state in
which it would be visible if Keyguard would not be hiding it. If that's not
the case, the request will fail immediately and
KeyguardDismissCallback#onDismissError will be invoked.
This value cannot be null . |
callback |
KeyguardManager.KeyguardDismissCallback : The callback to be called if the request to dismiss Keyguard was successful
or null if the caller isn't interested in knowing the result. The
callback will not be invoked if the activity was destroyed before the
callback was received. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2022-04-26 UTC.
-
Follow @AndroidDev on Twitter
-
Check out Android Developers on YouTube
-
Connect with the Android Developers community on LinkedIn
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK