Builder
open class Builder
kotlin.Any | |
↳ | android.hardware.biometrics.BiometricPrompt.Builder |
A builder that collects arguments to be shown on the system-provided biometric dialog.
Summary
Public constructors | |
---|---|
Creates a builder for a |
Public methods | |
---|---|
open BiometricPrompt |
build() Creates a |
open BiometricPrompt.Builder |
setAllowedAuthenticators(authenticators: Int) Optional: Specifies the type(s) of authenticators that may be invoked by |
open BiometricPrompt.Builder |
setConfirmationRequired(requireConfirmation: Boolean) Optional: Sets a hint to the system for whether to require user confirmation after authentication. |
open BiometricPrompt.Builder |
setContentView(view: PromptContentView) Optional: Sets application customized content view that will be shown on the prompt. |
open BiometricPrompt.Builder |
setDescription(description: CharSequence) Optional: Sets a description that will be shown on the prompt. |
open BiometricPrompt.Builder |
setDeviceCredentialAllowed(allowed: Boolean) Optional: If enabled, the user will be given the option to authenticate with their device PIN, pattern, or password. |
open BiometricPrompt.Builder |
setLogoBitmap(logoBitmap: Bitmap) Optional: Sets the bitmap drawable of the logo that will be shown on the prompt. |
open BiometricPrompt.Builder |
setLogoDescription(logoDescription: String) Optional: Sets logo description text that will be shown on the prompt. |
open BiometricPrompt.Builder |
setLogoRes(logoRes: Int) Optional: Sets the drawable resource of the logo that will be shown on the prompt. |
open BiometricPrompt.Builder |
setNegativeButton(text: CharSequence, executor: Executor, listener: DialogInterface.OnClickListener) Required: Sets the text, executor, and click listener for the negative button on the prompt. |
open BiometricPrompt.Builder |
setSubtitle(subtitle: CharSequence) Optional: Sets a subtitle that will be shown on the prompt. |
open BiometricPrompt.Builder |
setTitle(title: CharSequence) Required: Sets the title that will be shown on the prompt. |
Public constructors
Builder
Builder(context: Context!)
Creates a builder for a BiometricPrompt
dialog.
Parameters | |
---|---|
context |
Context!: The Context that will be used to build the prompt. |
Public methods
build
open fun build(): BiometricPrompt
Creates a BiometricPrompt
.
Return | |
---|---|
BiometricPrompt |
An instance of BiometricPrompt . This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If any required fields are unset, or if given any invalid combination of field values. |
setAllowedAuthenticators
open fun setAllowedAuthenticators(authenticators: Int): BiometricPrompt.Builder
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:
Authenticators.BIOMETRIC_WEAK
for non-crypto authentication, orAuthenticators.BIOMETRIC_STRONG
for crypto-based authentication.
If this method is used and no authenticator of any of the specified types is available at the time BiometricPrompt#authenticate(...)
is called, authentication will be canceled and AuthenticationCallback.onAuthenticationError(int, CharSequence)
will be invoked with an appropriate error code.
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 Authenticators.DEVICE_CREDENTIAL
) will replace the negative button on the prompt, making it an error to also call setNegativeButton(java.lang.CharSequence,java.util.concurrent.Executor,android.content.DialogInterface.OnClickListener)
.
If unlocking cryptographic operation(s), it is the application's responsibility to request authentication with the proper set of authenticators (e.g. match the authenticators specified during key generation).
Parameters | |
---|---|
authenticators |
Int: A bit field representing all valid authenticator types that may be invoked by the prompt. Value is either 0 or a combination of android.hardware.biometrics.BiometricManager.Authenticators#BIOMETRIC_STRONG , android.hardware.biometrics.BiometricManager.Authenticators#BIOMETRIC_WEAK , android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_CONVENIENCE, android.hardware.biometrics.BiometricManager.Authenticators#DEVICE_CREDENTIAL , and android.hardware.biometrics.BiometricManager.Authenticators.IDENTITY_CHECK |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setConfirmationRequired
open fun setConfirmationRequired(requireConfirmation: Boolean): BiometricPrompt.Builder
Optional: Sets a hint to the system for whether to require user confirmation after authentication. For example, implicit modalities like face and iris are passive, meaning they don't require an explicit user action to complete authentication. If set to true, these modalities should require the user to take some action (e.g. press a button) before AuthenticationCallback.onAuthenticationSucceeded(AuthenticationResult)
is called. Defaults to true.
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 just passes a hint to the system, which the system may then ignore. For example, a value of false may be ignored if the user has disabled implicit authentication in Settings, or if it does not apply to a particular modality (e.g. fingerprint).
Parameters | |
---|---|
requireConfirmation |
Boolean: true if explicit user confirmation should be required, or false otherwise. |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setContentView
open fun setContentView(view: PromptContentView): BiometricPrompt.Builder
Optional: Sets application customized content view that will be shown on the prompt.
Note that the description set by Builder.setDescription(CharSequence)
will be overridden by Builder.setContentView(PromptContentView)
. The view provided to Builder.setContentView(PromptContentView)
will be used if both methods are called.
Parameters | |
---|---|
view |
PromptContentView: The customized view information. This value cannot be null . |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setDescription
open fun setDescription(description: CharSequence): BiometricPrompt.Builder
Optional: Sets a description that will be shown on the prompt.
Note that the description set by Builder.setDescription(CharSequence)
will be overridden by Builder.setContentView(PromptContentView)
. The view provided to Builder.setContentView(PromptContentView)
will be used if both methods are called.
Parameters | |
---|---|
description |
CharSequence: The description to display. This value cannot be null . |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setDeviceCredentialAllowed
open funsetDeviceCredentialAllowed(allowed: Boolean): BiometricPrompt.Builder
Deprecated: Replaced by setAllowedAuthenticators(int)
.
Optional: If enabled, the user will be given the option to authenticate with their device PIN, pattern, or password. Developers should first check android.hardware.biometrics.BiometricManager#canAuthenticate(int)
for Authenticators.DEVICE_CREDENTIAL
before enabling. If the device is not secured with a credential, AuthenticationCallback.onAuthenticationError(int, CharSequence)
will be invoked with BiometricPrompt.BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL
. Defaults to false.
Note that enabling this option replaces the negative button on the prompt with one that allows the user to authenticate with their device credential, making it an error to call setNegativeButton(java.lang.CharSequence,java.util.concurrent.Executor,android.content.DialogInterface.OnClickListener)
.
Parameters | |
---|---|
allowed |
Boolean: true if the prompt should fall back to asking for the user's device credential (PIN/pattern/password), or false otherwise. |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setLogoBitmap
open fun setLogoBitmap(logoBitmap: Bitmap): BiometricPrompt.Builder
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.
Requires android.Manifest.permission#SET_BIOMETRIC_DIALOG_ADVANCED
Parameters | |
---|---|
logoBitmap |
Bitmap: A bitmap drawable of the logo that will be shown on the prompt. This value cannot be null . |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setLogoDescription
open fun setLogoDescription(logoDescription: String): BiometricPrompt.Builder
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.
Requires android.Manifest.permission#SET_BIOMETRIC_DIALOG_ADVANCED
Parameters | |
---|---|
logoDescription |
String: The logo description text that will be shown on the prompt. This value cannot be null . |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If logo description is null. |
setLogoRes
open fun setLogoRes(logoRes: Int): BiometricPrompt.Builder
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.
Requires android.Manifest.permission#SET_BIOMETRIC_DIALOG_ADVANCED
Parameters | |
---|---|
logoRes |
Int: A drawable resource of the logo that will be shown on the prompt. |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setNegativeButton
open fun setNegativeButton(
text: CharSequence,
executor: Executor,
listener: DialogInterface.OnClickListener
): BiometricPrompt.Builder
Required: Sets the text, executor, and click listener for the negative button on the prompt. This is typically a cancel button, but may be also used to show an alternative method for authentication, such as a screen that asks for a backup password.
Note that this setting is not required, and in fact is explicitly disallowed, if device credential authentication is enabled via setAllowedAuthenticators(int)
or setDeviceCredentialAllowed(boolean)
.
Parameters | |
---|---|
text |
CharSequence: Text to be shown on the negative button for the prompt. This value cannot be null . |
executor |
Executor: Executor that will be used to run the on click callback. This value cannot be null . Callback and listener events are dispatched through this Executor , providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor() . Otherwise, provide an Executor that dispatches to an appropriate thread. |
listener |
DialogInterface.OnClickListener: Listener containing a callback to be run when the button is pressed. This value cannot be null . |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setSubtitle
open fun setSubtitle(subtitle: CharSequence): BiometricPrompt.Builder
Optional: Sets a subtitle that will be shown on the prompt.
Parameters | |
---|---|
subtitle |
CharSequence: The subtitle to display. This value cannot be null . |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |
setTitle
open fun setTitle(title: CharSequence): BiometricPrompt.Builder
Required: Sets the title that will be shown on the prompt.
Parameters | |
---|---|
title |
CharSequence: The title to display. This value cannot be null . |
Return | |
---|---|
BiometricPrompt.Builder |
This builder. This value cannot be null . |