BiometricPrompt

public class BiometricPrompt
extends Object

java.lang.Object
   ↳ androidx.biometric.BiometricPrompt


A class that manages a system-provided biometric prompt. On devices running Android 9.0 (API 28) and above, this will show a system-provided authentication prompt, using one of the device's supported biometric modalities (fingerprint, iris, face, etc). Prior to Android 9.0, this will instead show a custom fingerprint authentication dialog. The prompt will persist across configuration changes unless explicitly canceled. For security reasons, the prompt will be dismissed when the client application is no longer in the foreground.

To persist authentication across configuration changes, developers should (re)create the prompt every time the activity/fragment is created. Instantiating the prompt with a new callback early in the fragment/activity lifecycle (e.g. in onCreate()) will allow the ongoing authentication session's callbacks to be received by the new fragment/activity instance. Note that cancelAuthentication() should not be called, and authenticate() does not need to be invoked during activity/fragment creation.

Summary

Nested classes

class BiometricPrompt.AuthenticationCallback

A collection of methods that may be invoked by BiometricPrompt during authentication. 

class BiometricPrompt.AuthenticationResult

A container for data passed to BiometricPrompt.AuthenticationCallback.onAuthenticationSucceeded(AuthenticationResult) when the user has successfully authenticated. 

class BiometricPrompt.CryptoObject

A wrapper class for the crypto objects supported by BiometricPrompt

class BiometricPrompt.PromptInfo

A set of configurable options for how the BiometricPrompt should appear and behave. 

Constants

int AUTHENTICATION_RESULT_TYPE_BIOMETRIC

Authentication type reported by BiometricPrompt.AuthenticationResult when the user authenticated by presenting some form of biometric (e.g.

int AUTHENTICATION_RESULT_TYPE_DEVICE_CREDENTIAL

Authentication type reported by BiometricPrompt.AuthenticationResult when the user authenticated by entering their device PIN, pattern, or password.

int AUTHENTICATION_RESULT_TYPE_UNKNOWN

Authentication type reported by BiometricPrompt.AuthenticationResult when the user authenticated via an unknown method.

int ERROR_CANCELED

The operation was canceled because the biometric sensor is unavailable.

int ERROR_HW_NOT_PRESENT

The device does not have the required authentication hardware.

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_DEVICE_CREDENTIAL

The device does not have pin, pattern, or password set up.

int ERROR_NO_SPACE

The operation can't be completed because there is not enough device storage remaining.

int ERROR_SECURITY_UPDATE_REQUIRED

A security vulnerability has been discovered with one or more hardware sensors.

int ERROR_TIMEOUT

The current operation has been running too long and has timed out.

int ERROR_UNABLE_TO_PROCESS

The sensor was unable to process the current image.

int ERROR_USER_CANCELED

The user canceled the operation.

int ERROR_VENDOR

The operation failed due to a vendor-specific error.

Public constructors

BiometricPrompt(FragmentActivity activity, BiometricPrompt.AuthenticationCallback callback)

Constructs a BiometricPrompt, which can be used to prompt the user to authenticate with a biometric such as fingerprint or face.

BiometricPrompt(Fragment fragment, BiometricPrompt.AuthenticationCallback callback)

Constructs a BiometricPrompt, which can be used to prompt the user to authenticate with a biometric such as fingerprint or face.

BiometricPrompt(FragmentActivity activity, Executor executor, BiometricPrompt.AuthenticationCallback callback)

Constructs a BiometricPrompt, which can be used to prompt the user to authenticate with a biometric such as fingerprint or face.

BiometricPrompt(Fragment fragment, Executor executor, BiometricPrompt.AuthenticationCallback callback)

Constructs a BiometricPrompt, which can be used to prompt the user to authenticate with a biometric such as fingerprint or face.

Public methods

void authenticate(BiometricPrompt.PromptInfo info, BiometricPrompt.CryptoObject crypto)

Shows the biometric prompt to the user.

void authenticate(BiometricPrompt.PromptInfo info)

Shows the biometric prompt to the user.

void cancelAuthentication()

Cancels the ongoing authentication session and dismisses the prompt.

Inherited methods