Google is committed to advancing racial equity for Black communities. See how.

BiometricPrompt.PromptInfo.Builder

public static class BiometricPrompt.PromptInfo.Builder
extends Object

java.lang.Object
   ↳ androidx.biometric.BiometricPrompt.PromptInfo.Builder


A builder used to set individual options for the BiometricPrompt.PromptInfo class.

Summary

Public constructors

Builder()

Public methods

BiometricPrompt.PromptInfo build()

Creates a BiometricPrompt.PromptInfo object with the specified options.

BiometricPrompt.PromptInfo.Builder setAllowedAuthenticators(int allowedAuthenticators)

Optional: Specifies the type(s) of authenticators that may be invoked by BiometricPrompt to authenticate the user.

BiometricPrompt.PromptInfo.Builder setConfirmationRequired(boolean confirmationRequired)

Optional: Sets a system hint for whether to require explicit user confirmation after a passive biometric (e.g.

BiometricPrompt.PromptInfo.Builder setDescription(CharSequence description)

Optional: Sets the description for the prompt.

BiometricPrompt.PromptInfo.Builder setDeviceCredentialAllowed(boolean deviceCredentialAllowed)

This method is deprecated. Use setAllowedAuthenticators(int) instead.

BiometricPrompt.PromptInfo.Builder setNegativeButtonText(CharSequence negativeButtonText)

Required: Sets the text for the negative button on the prompt.

BiometricPrompt.PromptInfo.Builder setSubtitle(CharSequence subtitle)

Optional: Sets the subtitle for the prompt.

BiometricPrompt.PromptInfo.Builder setTitle(CharSequence title)

Required: Sets the title for the prompt.

Inherited methods

Public constructors

Builder

public Builder ()

Public methods

build

public BiometricPrompt.PromptInfo build ()

Creates a BiometricPrompt.PromptInfo object with the specified options.

Returns
BiometricPrompt.PromptInfo The BiometricPrompt.PromptInfo object.

Throws
IllegalArgumentException If any required option is not set, or if any illegal combination of options is present.

setAllowedAuthenticators

public BiometricPrompt.PromptInfo.Builder setAllowedAuthenticators (int allowedAuthenticators)

Optional: Specifies the type(s) of authenticators that may be invoked by BiometricPrompt to authenticate the user. Available authenticator types are defined in BiometricManager.Authenticators and can be combined via bitwise OR. Defaults to:

Note that not all combinations of authenticator types are supported prior to Android 11 (API 30). Specifically, DEVICE_CREDENTIAL alone is unsupported prior to API 30, and BIOMETRIC_STRONG | DEVICE_CREDENTIAL is unsupported on API 28-29. Setting an unsupported value on an affected Android version will result in an error when calling build().

This method should be preferred over setDeviceCredentialAllowed(boolean) and overrides the latter if both are used. Using this method to enable device credential authentication (with BiometricManager.Authenticators.DEVICE_CREDENTIAL) will replace the negative button on the prompt, making it an error to also call setNegativeButtonText(CharSequence).

If this method is used and no authenticator of any of the specified types is available at the time authenticate() is called, BiometricPrompt.AuthenticationCallback.onAuthenticationError(int, CharSequence) will be invoked with an appropriate error code.

Parameters
allowedAuthenticators int: A bit field representing all valid authenticator types that may be invoked by the prompt.

Returns
BiometricPrompt.PromptInfo.Builder This builder.

setConfirmationRequired

public BiometricPrompt.PromptInfo.Builder setConfirmationRequired (boolean confirmationRequired)

Optional: Sets a system hint for whether to require explicit user confirmation after a passive biometric (e.g. iris or face) has been recognized but before BiometricPrompt.AuthenticationCallback.onAuthenticationSucceeded(AuthenticationResult) is called. Defaults to true.

Disabling this option is generally only appropriate for frequent, low-value transactions, such as re-authenticating for a previously authorized application.

Also note that, as it is merely a hint, this option may be ignored by the system. For example, the system may choose to instead always require confirmation if the user has disabled passive authentication for their device in Settings. Additionally, this option will be ignored on devices running OS versions prior to Android 10 (API 29).

Parameters
confirmationRequired boolean: Whether this option should be enabled.

Returns
BiometricPrompt.PromptInfo.Builder This builder.

setDescription

public BiometricPrompt.PromptInfo.Builder setDescription (CharSequence description)

Optional: Sets the description for the prompt.

Parameters
description CharSequence: The description to be displayed on the prompt.

Returns
BiometricPrompt.PromptInfo.Builder This builder.

setDeviceCredentialAllowed

public BiometricPrompt.PromptInfo.Builder setDeviceCredentialAllowed (boolean deviceCredentialAllowed)

This method is deprecated.
Use setAllowedAuthenticators(int) instead.

Optional: Sets whether the user should be given the option to authenticate with their device PIN, pattern, or password instead of a biometric. Defaults to false.

Note that this option is incompatible with setNegativeButtonText(CharSequence) and must NOT be enabled if the latter is set.

Before enabling this option, developers should check whether the device is secure by calling KeyguardManager.isDeviceSecure(). If the device is not secure, authentication will fail with BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL.

On versions prior to Android 10 (API 29), calls to BiometricPrompt.cancelAuthentication() will not work as expected after the user has chosen to authenticate with their device credential. This is because the library internally launches a separate activity (by calling KeyguardManager.createConfirmDeviceCredentialIntent(CharSequence, CharSequence)) that does not have a public API for cancellation.

Parameters
deviceCredentialAllowed boolean: Whether this option should be enabled.

Returns
BiometricPrompt.PromptInfo.Builder This builder.

setNegativeButtonText

public BiometricPrompt.PromptInfo.Builder setNegativeButtonText (CharSequence negativeButtonText)

Required: Sets the text for the negative button on the prompt.

Note that this option is incompatible with device credential authentication and must NOT be set if the latter is enabled via setAllowedAuthenticators(int) or setDeviceCredentialAllowed(boolean).

Parameters
negativeButtonText CharSequence: The label to be used for the negative button on the prompt.

Returns
BiometricPrompt.PromptInfo.Builder This builder.

setSubtitle

public BiometricPrompt.PromptInfo.Builder setSubtitle (CharSequence subtitle)

Optional: Sets the subtitle for the prompt.

Parameters
subtitle CharSequence: The subtitle to be displayed on the prompt.

Returns
BiometricPrompt.PromptInfo.Builder This builder.

setTitle

public BiometricPrompt.PromptInfo.Builder setTitle (CharSequence title)

Required: Sets the title for the prompt.

Parameters
title CharSequence: The title to be displayed on the prompt.

Returns
BiometricPrompt.PromptInfo.Builder This builder.