BiometricPrompt.PromptInfo.Builder
public class BiometricPrompt.PromptInfo.Builder
A builder used to set individual options for the PromptInfo class.
Summary
Public constructors |
|---|
Builder() |
Public methods |
|
|---|---|
@NonNull BiometricPrompt.PromptInfo |
build()Creates a |
@NonNull BiometricPrompt.PromptInfo.Builder |
setAllowedAuthenticators(int allowedAuthenticators)Optional: Specifies the type(s) of authenticators that may be invoked by |
@NonNull 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 |
@NonNull BiometricPrompt.PromptInfo.Builder |
Optional: Sets application customized content view that will be shown on the prompt. |
@NonNull BiometricPrompt.PromptInfo.Builder |
setDescription(@Nullable CharSequence description)Optional: Sets a description that will be shown on the prompt. |
@NonNull BiometricPrompt.PromptInfo.Builder |
This method is deprecated. Use |
@NonNull BiometricPrompt.PromptInfo.Builder |
@RequiresPermission(value = "android.permission.SET_BIOMETRIC_DIALOG_ADVANCED")Optional: Sets the bitmap drawable of the logo that will be shown on the prompt. |
@NonNull BiometricPrompt.PromptInfo.Builder |
@RequiresPermission(value = "android.permission.SET_BIOMETRIC_DIALOG_ADVANCED")Optional: Sets logo description text that will be shown on the prompt. |
@NonNull BiometricPrompt.PromptInfo.Builder |
@RequiresPermission(value = "android.permission.SET_BIOMETRIC_DIALOG_ADVANCED")Optional: Sets the drawable resource of the logo that will be shown on the prompt. |
@NonNull BiometricPrompt.PromptInfo.Builder |
setNegativeButtonText(@NonNull CharSequence negativeButtonText)Required: Sets the text for the negative button on the prompt. |
@NonNull BiometricPrompt.PromptInfo.Builder |
setSubtitle(@Nullable CharSequence subtitle)Optional: Sets the subtitle for the prompt. |
@NonNull BiometricPrompt.PromptInfo.Builder |
setTitle(@NonNull CharSequence title)Required: Sets the title for the prompt. |
Public constructors
Public methods
build
public @NonNull BiometricPrompt.PromptInfo build()
Creates a PromptInfo object with the specified options.
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo |
The |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If any required option is not set, or if any illegal combination of options is present. |
setAllowedAuthenticators
public @NonNull 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 Authenticators and can be combined via bitwise OR. Defaults to:
BIOMETRIC_WEAKfor non-crypto authentication, orBIOMETRIC_STRONGfor crypto-based authentication.
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 and overrides the latter if both are used. Using this method to enable device credential authentication (with DEVICE_CREDENTIAL) will replace the negative button on the prompt, making it an error to also call setNegativeButtonText.
If this method is used and no authenticator of any of the specified types is available at the time authenticate() is called, onAuthenticationError will be invoked with an appropriate error code.
| Parameters | |
|---|---|
int allowedAuthenticators |
A bit field representing all valid authenticator types that may be invoked by the prompt. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
setConfirmationRequired
public @NonNull 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 onAuthenticationSucceeded 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 | |
|---|---|
boolean confirmationRequired |
Whether this option should be enabled. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
setContentView
public @NonNull BiometricPrompt.PromptInfo.Builder setContentView(@NonNull PromptContentView view)
Optional: Sets application customized content view that will be shown on the prompt.
Note that from API 35, the description set by setDescription will be overridden by setContentView. The view provided to setContentView will be used if both methods are called.
| Parameters | |
|---|---|
@NonNull PromptContentView view |
The customized view information. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
setDescription
public @NonNull BiometricPrompt.PromptInfo.Builder setDescription(@Nullable CharSequence description)
Optional: Sets a description that will be shown on the prompt.
Note that from API 35, the description set by setDescription will be overridden by setContentView. The view provided to setContentView will be used if both methods are called.
| Parameters | |
|---|---|
@Nullable CharSequence description |
The description to display. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
public @NonNull BiometricPrompt.PromptInfo.BuildersetDeviceCredentialAllowed(boolean deviceCredentialAllowed)
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 and must NOT be enabled if the latter is set.
Before enabling this option, developers should check whether the device is secure by calling isDeviceSecure. If the device is not secure, authentication will fail with ERROR_NO_DEVICE_CREDENTIAL.
On versions prior to Android 10 (API 29), calls to 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 createConfirmDeviceCredentialIntent) that does not have a public API for cancellation.
| Parameters | |
|---|---|
boolean deviceCredentialAllowed |
Whether this option should be enabled. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
setLogoBitmap
@RequiresPermission(value = "android.permission.SET_BIOMETRIC_DIALOG_ADVANCED")
public @NonNull BiometricPrompt.PromptInfo.Builder setLogoBitmap(@NonNull Bitmap logoBitmap)
Optional: Sets the bitmap drawable of the logo that will be shown on the prompt.
Note that using this method is not recommended in most scenarios because the calling application's icon will be used by default. Setting the logo is intended for large bundled applications that perform a wide range of functions and need to show distinct icons for each function.
| Parameters | |
|---|---|
@NonNull Bitmap logoBitmap |
A bitmap drawable of the logo that will be shown on the prompt. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
setLogoDescription
@RequiresPermission(value = "android.permission.SET_BIOMETRIC_DIALOG_ADVANCED")
public @NonNull BiometricPrompt.PromptInfo.Builder setLogoDescription(@NonNull String logoDescription)
Optional: Sets logo description text that will be shown on the prompt.
Note that using this method is not recommended in most scenarios because the calling application's name will be used by default. Setting the logo description is intended for large bundled applications that perform a wide range of functions and need to show distinct description for each function.
| Parameters | |
|---|---|
@NonNull String logoDescription |
The logo description text that will be shown on the prompt. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If logo description is null or exceeds certain character limit. |
setLogoRes
@RequiresPermission(value = "android.permission.SET_BIOMETRIC_DIALOG_ADVANCED")
public @NonNull BiometricPrompt.PromptInfo.Builder setLogoRes(@DrawableRes int logoRes)
Optional: Sets the drawable resource of the logo that will be shown on the prompt.
Note that using this method is not recommended in most scenarios because the calling application's icon will be used by default. Setting the logo is intended for large bundled applications that perform a wide range of functions and need to show distinct icons for each function.
| Parameters | |
|---|---|
@DrawableRes int logoRes |
A drawable resource of the logo that will be shown on the prompt. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
setNegativeButtonText
public @NonNull BiometricPrompt.PromptInfo.Builder setNegativeButtonText(@NonNull 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 or setDeviceCredentialAllowed.
| Parameters | |
|---|---|
@NonNull CharSequence negativeButtonText |
The label to be used for the negative button on the prompt. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
setSubtitle
public @NonNull BiometricPrompt.PromptInfo.Builder setSubtitle(@Nullable CharSequence subtitle)
Optional: Sets the subtitle for the prompt.
| Parameters | |
|---|---|
@Nullable CharSequence subtitle |
The subtitle to be displayed on the prompt. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |
setTitle
public @NonNull BiometricPrompt.PromptInfo.Builder setTitle(@NonNull CharSequence title)
Required: Sets the title for the prompt.
| Parameters | |
|---|---|
@NonNull CharSequence title |
The title to be displayed on the prompt. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.PromptInfo.Builder |
This builder. |