Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

BiometricPrompt.PromptInfo.Builder

public static class BiometricPrompt.PromptInfo.Builder
extends Object

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


A builder that collects arguments to be shown on the system-provided biometric dialog.

Summary

Public constructors

BiometricPrompt.PromptInfo.Builder()

Public methods

BiometricPrompt.PromptInfo build()

Creates a BiometricPrompt.

BiometricPrompt.PromptInfo.Builder setConfirmationRequired(boolean requireConfirmation)

Optional: A hint to the system to require user confirmation after a biometric has been authenticated.

BiometricPrompt.PromptInfo.Builder setDescription(CharSequence description)

Optional: Set the description to display.

BiometricPrompt.PromptInfo.Builder setDeviceCredentialAllowed(boolean enable)

The user will first be prompted to authenticate with biometrics, but also given the option to authenticate with their device PIN, pattern, or password.

BiometricPrompt.PromptInfo.Builder setNegativeButtonText(CharSequence text)

Required: Set the text for the negative button.

BiometricPrompt.PromptInfo.Builder setSubtitle(CharSequence subtitle)

Optional: Set the subtitle to display.

BiometricPrompt.PromptInfo.Builder setTitle(CharSequence title)

Required: Set the title to display.

Inherited methods

Public constructors

BiometricPrompt.PromptInfo.Builder

public BiometricPrompt.PromptInfo.Builder ()

Public methods

build

public BiometricPrompt.PromptInfo build ()

Creates a BiometricPrompt.

Returns
BiometricPrompt.PromptInfo a BiometricPrompt

Throws
IllegalArgumentException if any of the required fields are not set.

setConfirmationRequired

public BiometricPrompt.PromptInfo.Builder setConfirmationRequired (boolean requireConfirmation)

Optional: A hint to the system to require user confirmation after a biometric has been authenticated. For example, implicit modalities like Face and Iris authentication are passive, meaning they don't require an explicit user action to complete. When set to 'false', the user action (e.g. pressing a button) will not be required. BiometricPrompt will require confirmation by default. A typical use case for not requiring confirmation would be for low-risk transactions, such as re-authenticating a recently authenticated application. A typical use case for requiring confirmation would be for authorizing a purchase. Note that this is a hint to the system. The system may choose to ignore the flag. For example, if the user disables implicit authentication in Settings, or if it does not apply to a modality (e.g. Fingerprint). When ignored, the system will default to requiring confirmation. This method only applies to Q and above.

Parameters
requireConfirmation boolean

Returns
BiometricPrompt.PromptInfo.Builder

setDescription

public BiometricPrompt.PromptInfo.Builder setDescription (CharSequence description)

Optional: Set the description to display.

Parameters
description CharSequence

Returns
BiometricPrompt.PromptInfo.Builder

setDeviceCredentialAllowed

public BiometricPrompt.PromptInfo.Builder setDeviceCredentialAllowed (boolean enable)

The user will first be prompted to authenticate with biometrics, but also given the option to authenticate with their device PIN, pattern, or password. Developers should first check KeyguardManager.isDeviceSecure() before enabling this. If the device is not secure, BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL will be returned in BiometricPrompt.AuthenticationCallback.onAuthenticationError(int, CharSequence).

Note that setNegativeButtonText(CharSequence) should not be set if this is set to true.

On versions P and below, once the device credential prompt is shown, BiometricPrompt.cancelAuthentication() will not work, since the library internally launches KeyguardManager.createConfirmDeviceCredentialIntent(CharSequence, CharSequence), which does not have a public API for cancellation.

Parameters
enable boolean: When true, the prompt will fall back to ask for the user's device credentials (PIN, pattern, or password).

Returns
BiometricPrompt.PromptInfo.Builder

setNegativeButtonText

public BiometricPrompt.PromptInfo.Builder setNegativeButtonText (CharSequence text)

Required: Set the text for the negative button. This would typically be used as a "Cancel" button, but may be also used to show an alternative method for authentication, such as screen that asks for a backup password.

Parameters
text CharSequence

Returns
BiometricPrompt.PromptInfo.Builder

setSubtitle

public BiometricPrompt.PromptInfo.Builder setSubtitle (CharSequence subtitle)

Optional: Set the subtitle to display.

Parameters
subtitle CharSequence

Returns
BiometricPrompt.PromptInfo.Builder

setTitle

public BiometricPrompt.PromptInfo.Builder setTitle (CharSequence title)

Required: Set the title to display.

Parameters
title CharSequence

Returns
BiometricPrompt.PromptInfo.Builder