BiometricPrompt
public
class
BiometricPrompt
extends Object
| java.lang.Object | |
| ↳ | androidx.biometric.BiometricPrompt |
A class that manages a system-provided biometric prompt. On devices running P and above, this will show a system-provided authentication prompt, using a device's supported biometric (fingerprint, iris, face, etc). On devices before P, this will show a dialog prompting for fingerprint authentication. The prompt will persist across orientation changes unless explicitly canceled by the client. For security reasons, the prompt will automatically dismiss when the activity is no longer in the foreground.
Summary
Nested classes | |
|---|---|
class |
BiometricPrompt.AuthenticationCallback
Callback structure provided to |
class |
BiometricPrompt.AuthenticationResult
Container for callback data from |
class |
BiometricPrompt.CryptoObject
A wrapper class for the crypto objects supported by BiometricPrompt. |
class |
BiometricPrompt.PromptInfo
A class that contains a builder which returns the |
Constants | |
|---|---|
int |
ERROR_CANCELED
The operation was canceled because the biometric sensor is unavailable. |
int |
ERROR_HW_NOT_PRESENT
The device does not have a biometric sensor. |
int |
ERROR_HW_UNAVAILABLE
The hardware is unavailable. |
int |
ERROR_LOCKOUT
The operation was canceled because the API is locked out due to too many attempts. |
int |
ERROR_LOCKOUT_PERMANENT
The operation was canceled because ERROR_LOCKOUT occurred too many times. |
int |
ERROR_NEGATIVE_BUTTON
The user pressed the negative button. |
int |
ERROR_NO_BIOMETRICS
The user does not have any biometrics enrolled. |
int |
ERROR_NO_SPACE
Error state returned for operations like enrollment; the operation cannot be completed because there's not enough storage remaining to complete the operation. |
int |
ERROR_TIMEOUT
Error state returned when the current request has been running too long. |
int |
ERROR_UNABLE_TO_PROCESS
Error state returned when the sensor was unable to process the current image. |
int |
ERROR_USER_CANCELED
The user canceled the operation. |
int |
ERROR_VENDOR
Hardware vendors may extend this list if there are conditions that do not fall under one of the above categories. |
Public constructors | |
|---|---|
BiometricPrompt(FragmentActivity fragmentActivity, Executor executor, BiometricPrompt.AuthenticationCallback callback)
Constructs a |
|
Public methods | |
|---|---|
void
|
authenticate(BiometricPrompt.PromptInfo info, BiometricPrompt.CryptoObject crypto)
Shows the biometric prompt. |
void
|
authenticate(BiometricPrompt.PromptInfo info)
Shows the biometric prompt. |
void
|
cancelAuthentication()
Cancels the biometric authentication, and dismisses the dialog upon confirmation from the biometric service. |
Inherited methods | |
|---|---|
Constants
ERROR_CANCELED
public static final int ERROR_CANCELED
The operation was canceled because the biometric sensor is unavailable. For example, this may happen when the user is switched, the device is locked or another pending operation prevents or disables it.
Constant Value: 5 (0x00000005)
ERROR_HW_NOT_PRESENT
public static final int ERROR_HW_NOT_PRESENT
The device does not have a biometric sensor.
Constant Value: 12 (0x0000000c)
ERROR_HW_UNAVAILABLE
public static final int ERROR_HW_UNAVAILABLE
The hardware is unavailable. Try again later.
Constant Value: 1 (0x00000001)
ERROR_LOCKOUT
public static final int ERROR_LOCKOUT
The operation was canceled because the API is locked out due to too many attempts. This occurs after 5 failed attempts, and lasts for 30 seconds.
Constant Value: 7 (0x00000007)
ERROR_LOCKOUT_PERMANENT
public static final int ERROR_LOCKOUT_PERMANENT
The operation was canceled because ERROR_LOCKOUT occurred too many times. Biometric authentication is disabled until the user unlocks with strong authentication (PIN/Pattern/Password)
Constant Value: 9 (0x00000009)
ERROR_NEGATIVE_BUTTON
public static final int ERROR_NEGATIVE_BUTTON
The user pressed the negative button.
Constant Value: 13 (0x0000000d)
ERROR_NO_BIOMETRICS
public static final int ERROR_NO_BIOMETRICS
The user does not have any biometrics enrolled.
Constant Value: 11 (0x0000000b)
ERROR_NO_SPACE
public static final int ERROR_NO_SPACE
Error state returned for operations like enrollment; the operation cannot be completed because there's not enough storage remaining to complete the operation.
Constant Value: 4 (0x00000004)
ERROR_TIMEOUT
public static final int ERROR_TIMEOUT
Error state returned when the current request has been running too long. This is intended to prevent programs from waiting for the biometric sensor indefinitely. The timeout is platform and sensor-specific, but is generally on the order of 30 seconds.
Constant Value: 3 (0x00000003)
ERROR_UNABLE_TO_PROCESS
public static final int ERROR_UNABLE_TO_PROCESS
Error state returned when the sensor was unable to process the current image.
Constant Value: 2 (0x00000002)
ERROR_USER_CANCELED
public static final int ERROR_USER_CANCELED
The user canceled the operation. Upon receiving this, applications should use alternate
authentication (e.g. a password). The application should also provide the means to return to
biometric authentication, such as a "use
Constant Value: 10 (0x0000000a)
ERROR_VENDOR
public static final int ERROR_VENDOR
Hardware vendors may extend this list if there are conditions that do not fall under one of the above categories. Vendors are responsible for providing error strings for these errors. These messages are typically reserved for internal operations such as enrollment, but may be used to express vendor errors not otherwise covered. Applications are expected to show the error message string if they happen, but are advised not to rely on the message id since they will be device and vendor-specific
Constant Value: 8 (0x00000008)
Public constructors
BiometricPrompt
public BiometricPrompt (FragmentActivity fragmentActivity, Executor executor, BiometricPrompt.AuthenticationCallback callback)
Constructs a BiometricPrompt which can be used to prompt the user for
authentication. The authenticaton prompt created by
authenticate(PromptInfo, CryptoObject) and
authenticate(PromptInfo) will persist across device
configuration changes by default. If authentication is in progress, re-creating
the BiometricPrompt can be used to update the Executor and
BiometricPrompt.AuthenticationCallback. This should be used to update the
BiometricPrompt.AuthenticationCallback after configuration changes.
such as FragmentActivity.onCreate(Bundle).
| Parameters | |
|---|---|
fragmentActivity |
FragmentActivity: A reference to the client's activity. |
executor |
Executor: An executor to handle callback events. |
callback |
BiometricPrompt.AuthenticationCallback: An object to receive authentication events.
|
Public methods
authenticate
public void authenticate (BiometricPrompt.PromptInfo info, BiometricPrompt.CryptoObject crypto)
Shows the biometric prompt. The prompt survives lifecycle changes by default. To cancel the
authentication, use cancelAuthentication().
| Parameters | |
|---|---|
info |
BiometricPrompt.PromptInfo: The information that will be displayed on the prompt. Create this object using
BiometricPrompt.PromptInfo.Builder. |
crypto |
BiometricPrompt.CryptoObject: The crypto object associated with the authentication.
|
authenticate
public void authenticate (BiometricPrompt.PromptInfo info)
Shows the biometric prompt. The prompt survives lifecycle changes by default. To cancel the
authentication, use cancelAuthentication().
| Parameters | |
|---|---|
info |
BiometricPrompt.PromptInfo: The information that will be displayed on the prompt. Create this object using
BiometricPrompt.PromptInfo.Builder.
|
cancelAuthentication
public void cancelAuthentication ()
Cancels the biometric authentication, and dismisses the dialog upon confirmation from the biometric service.
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.