The Android Developer Challenge is back! Submit your idea before December 2.

BiometricPrompt

open class BiometricPrompt : BiometricConstants
kotlin.Any
   ↳ 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 configuration changes unless explicitly canceled by the client. For security reasons, the prompt will automatically dismiss when the application is no longer in the foreground. To persist authentication across configuration changes, developers should (re)create the BiometricPrompt every time the activity/fragment is created. Instantiating the library with a new callback early in the fragment/activity lifecycle (e.g. onCreate) allows the ongoing authenticate session's callbacks to be received by the new fragment/activity. Note that BiometricPrompt#cancelAuthentication() should not be called, and BiometricPrompt#authenticate(PromptInfo) or BiometricPrompt#authenticate(PromptInfo, CryptoObject) does not need to be invoked after the new activity/fragment is created, since we are keeping/continuing the same session.

Summary

Nested classes

abstract

Callback structure provided to BiometricPrompt.

open

Container for callback data from authenticate(PromptInfo) and authenticate(PromptInfo, CryptoObject).

open

A wrapper class for the crypto objects supported by BiometricPrompt.

open

A class that contains a builder which returns the PromptInfo to be used in authenticate(PromptInfo, CryptoObject) and authenticate(PromptInfo).

Public constructors

<init>(@NonNull fragmentActivity: FragmentActivity, @NonNull executor: Executor, @NonNull callback: BiometricPrompt.AuthenticationCallback)

Constructs a BiometricPrompt which can be used to prompt the user for authentication.

<init>(@NonNull fragment: Fragment, @NonNull executor: Executor, @NonNull callback: BiometricPrompt.AuthenticationCallback)

Constructs a BiometricPrompt which can be used to prompt the user for authentication.

Public methods

open Unit

Shows the biometric prompt.

open Unit

Shows the biometric prompt.

open Unit

Cancels the biometric authentication, and dismisses the dialog upon confirmation from the biometric service.

Public constructors

<init>

BiometricPrompt(@NonNull fragmentActivity: FragmentActivity, @NonNull executor: Executor, @NonNull callback: BiometricPrompt.AuthenticationCallback)

Constructs a BiometricPrompt which can be used to prompt the user for authentication. The authentication prompt created by BiometricPrompt#authenticate(PromptInfo, CryptoObject) and BiometricPrompt#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 AuthenticationCallback. This should be used to update the AuthenticationCallback after configuration changes. such as FragmentActivity#onCreate(Bundle).

Parameters
fragmentActivity FragmentActivity: A reference to the client's activity.
executor FragmentActivity: An executor to handle callback events.
callback FragmentActivity: An object to receive authentication events.

<init>

BiometricPrompt(@NonNull fragment: Fragment, @NonNull executor: Executor, @NonNull callback: BiometricPrompt.AuthenticationCallback)

Constructs a BiometricPrompt which can be used to prompt the user for authentication. The authentication prompt created by BiometricPrompt#authenticate(PromptInfo, CryptoObject) and BiometricPrompt#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 AuthenticationCallback. This should be used to update the AuthenticationCallback after configuration changes. such as Fragment#onCreate(Bundle).

Parameters
fragment Fragment: A reference to the client's fragment.
executor Fragment: An executor to handle callback events.
callback Fragment: An object to receive authentication events.

Public methods

authenticate

open fun authenticate(@NonNull info: BiometricPrompt.PromptInfo, @NonNull crypto: BiometricPrompt.CryptoObject): Unit

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.PromptInfo: The crypto object associated with the authentication.

authenticate

open fun authenticate(@NonNull info: BiometricPrompt.PromptInfo): Unit

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

open fun cancelAuthentication(): Unit

Cancels the biometric authentication, and dismisses the dialog upon confirmation from the biometric service.

On P or below, calling this method when the device credential prompt is shown will NOT work as expected. See PromptInfo.Builder#setDeviceCredentialAllowed(boolean) for more details.