Builder
open class Builder
kotlin.Any | |
↳ | androidx.biometric.BiometricPrompt.PromptInfo.Builder |
A builder that collects arguments to be shown on the system-provided biometric dialog.
Summary
Public constructors |
|
---|---|
<init>() A builder that collects arguments to be shown on the system-provided biometric dialog. |
Public methods |
|
---|---|
open BiometricPrompt.PromptInfo |
build() Creates a |
open BiometricPrompt.PromptInfo.Builder |
setConfirmationRequired(requireConfirmation: Boolean) Optional: A hint to the system to require user confirmation after a biometric has been authenticated. |
open BiometricPrompt.PromptInfo.Builder |
setDescription(@Nullable description: CharSequence?) Optional: Set the description to display. |
open BiometricPrompt.PromptInfo.Builder |
setDeviceCredentialAllowed(enable: Boolean) The user will first be prompted to authenticate with biometrics, but also given the option to authenticate with their device PIN, pattern, or password. |
open BiometricPrompt.PromptInfo.Builder |
setNegativeButtonText(@NonNull text: CharSequence) Required: Set the text for the negative button. |
open BiometricPrompt.PromptInfo.Builder |
setSubtitle(@Nullable subtitle: CharSequence?) Optional: Set the subtitle to display. |
open BiometricPrompt.PromptInfo.Builder |
setTitle(@NonNull title: CharSequence) Required: Set the title to display. |
Public constructors
<init>
Builder()
A builder that collects arguments to be shown on the system-provided biometric dialog.
Public methods
build
@NonNull open fun build(): BiometricPrompt.PromptInfo
Creates a BiometricPrompt
.
Return | |
---|---|
BiometricPrompt.PromptInfo: a BiometricPrompt |
Exceptions | |
---|---|
IllegalArgumentException |
if any of the required fields are not set. |
setConfirmationRequired
@NonNull open fun setConfirmationRequired(requireConfirmation: Boolean): BiometricPrompt.PromptInfo.Builder
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.
setDescription
@NonNull open fun setDescription(@Nullable description: CharSequence?): BiometricPrompt.PromptInfo.Builder
Optional: Set the description to display.
setDeviceCredentialAllowed
@NonNull open fun setDeviceCredentialAllowed(enable: Boolean): BiometricPrompt.PromptInfo.Builder
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 android.app.KeyguardManager#isDeviceSecure()
before enabling this. If the device is not secure, BiometricPrompt#ERROR_NO_DEVICE_CREDENTIAL
will be returned in AuthenticationCallback#onAuthenticationError(int, CharSequence)
.
Note that Builder#setNegativeButtonText(CharSequence)
should not be set if this is set to true.
On versions P and below, once the device credential prompt is shown, cancelAuthentication()
will not work, since the library internally launches android.app.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). |
setNegativeButtonText
@NonNull open fun setNegativeButtonText(@NonNull text: CharSequence): BiometricPrompt.PromptInfo.Builder
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.
setSubtitle
@NonNull open fun setSubtitle(@Nullable subtitle: CharSequence?): BiometricPrompt.PromptInfo.Builder
Optional: Set the subtitle to display.
setTitle
@NonNull open fun setTitle(@NonNull title: CharSequence): BiometricPrompt.PromptInfo.Builder
Required: Set the title to display.