Builder


class Builder
kotlin.Any
   ↳ android.hardware.biometrics.EmbeddedBiometricPrompt.Builder

A builder for the embedded version of BiometricPrompt that collects arguments to be shown on the system-provided biometric dialog.

Summary

Public constructors
Builder(context: Context)

Creates a builder for an embedded BiometricPrompt dialog.

Public methods
EmbeddedBiometricPrompt.Builder
addFallbackOption(text: CharSequence, iconType: Int, executor: Executor, listener: DialogInterface.OnClickListener)

Optional: Sets the text, icon, executor, and click listener for a fallback option.

EmbeddedBiometricPrompt

Creates an EmbeddedBiometricPrompt.

EmbeddedBiometricPrompt.Builder
setAllowedAuthenticators(authenticators: Int)

Optional: Specifies the type(s) of authenticators that may be invoked.

EmbeddedBiometricPrompt.Builder

Optional: Sets the authentication callback and executor.

EmbeddedBiometricPrompt.Builder

Optional: Sets the authentication purpose for the prompt.

EmbeddedBiometricPrompt.Builder
setConfirmationRequired(requireConfirmation: Boolean)

Optional: Sets a hint to the system for whether to require user confirmation after authentication.

EmbeddedBiometricPrompt.Builder

Optional: Sets application customized content view that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

EmbeddedBiometricPrompt.Builder

Optional: Sets a description that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

EmbeddedBiometricPrompt.Builder

Sets the factory that will create the content to display above the biometric prompt as a connected sheet.

EmbeddedBiometricPrompt.Builder

Optional: Sets the id for an existing authentication session.

EmbeddedBiometricPrompt.Builder
setLogoBitmap(logoBitmap: Bitmap)

Optional: Sets the bitmap drawable of the logo that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

EmbeddedBiometricPrompt.Builder
setLogoDescription(logoDescription: String)

Optional: Sets logo description text that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

EmbeddedBiometricPrompt.Builder
setLogoRes(logoRes: Int)

Optional: Sets the drawable resource of the logo that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

EmbeddedBiometricPrompt.Builder

Optional: Sets the text, executor, and click listener for the negative button on the prompt.

EmbeddedBiometricPrompt.Builder
setNextTranslationOffset(nextTranslationOffset: Int)

Optional: Sets the ending target layout translation offset in pixels (px) for the disappear (exit) animation of the biometric prompt.

EmbeddedBiometricPrompt.Builder
setPreviousTranslationOffset(previousTranslationOffset: Int)

Optional: Sets the starting layout translation offset in pixels (px) for the appear (entry) animation of the biometric prompt.

EmbeddedBiometricPrompt.Builder

Optional: Sets a subtitle that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

EmbeddedBiometricPrompt.Builder

Required: Sets the title that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

Public constructors

Builder

Builder(context: Context)

Creates a builder for an embedded BiometricPrompt dialog.

Parameters
context Context: The Context that will be used to build the prompt.
This value cannot be null.

Public methods

addFallbackOption

fun addFallbackOption(
    text: CharSequence,
    iconType: Int,
    executor: Executor,
    listener: DialogInterface.OnClickListener
): EmbeddedBiometricPrompt.Builder

Optional: Sets the text, icon, executor, and click listener for a fallback option.

Parameters
text CharSequence: The text to display for the fallback option.
This value cannot be null.
iconType Int: The icon to display for the fallback option.
Value is one of the following:
executor Executor: The executor to use for the click listener.
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: The click listener to use for the fallback option.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

build

fun build(): EmbeddedBiometricPrompt

Creates an EmbeddedBiometricPrompt.

Return
EmbeddedBiometricPrompt The created EmbeddedBiometricPrompt.
This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if the factory to create embedded content is not provided.

setAllowedAuthenticators

fun setAllowedAuthenticators(authenticators: Int): EmbeddedBiometricPrompt.Builder

Optional: Specifies the type(s) of authenticators that may be invoked.

Parameters
authenticators Int: A bit field representing the type(s) of authenticators that may be invoked by the prompt.
Value is either 0 or a combination of the following:
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setAuthenticationCallback

fun setAuthenticationCallback(
    executor: Executor,
    callback: EmbeddedBiometricPrompt.AuthenticationCallback
): EmbeddedBiometricPrompt.Builder

Optional: Sets the authentication callback and executor.

Parameters
executor Executor: The executor to use for the authentication 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.
callback EmbeddedBiometricPrompt.AuthenticationCallback: The authentication callback.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setAuthenticationPurpose

fun setAuthenticationPurpose(purpose: Int): EmbeddedBiometricPrompt.Builder

Optional: Sets the authentication purpose for the prompt.

Provides a hint to customize the BiometricPrompt appearance to clarify what the user is authorizing. This is cosmetic only, can vary by device, and does not change security guarantees (see setAllowedAuthenticators(int)).

For example, this may inform the user to click or tap "to pay" instead of "to authenticate".

Parameters
purpose Int: The authentication purpose to set.
Value is one of the following:
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setConfirmationRequired

fun setConfirmationRequired(requireConfirmation: Boolean): EmbeddedBiometricPrompt.Builder

Optional: Sets a hint to the system for whether to require user confirmation after authentication.

Parameters
requireConfirmation Boolean: Whether to require user confirmation.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setContentView

fun setContentView(view: PromptContentView): EmbeddedBiometricPrompt.Builder

Optional: Sets application customized content view that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

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 to display on the credential page.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setDescription

fun setDescription(description: CharSequence): EmbeddedBiometricPrompt.Builder

Optional: Sets a description that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

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 on the credential page.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setEmbeddedContentFactory

fun setEmbeddedContentFactory(contentFactory: EmbeddedBiometricPrompt.EmbeddedContentFactory): EmbeddedBiometricPrompt.Builder

Sets the factory that will create the content to display above the biometric prompt as a connected sheet.

Parameters
contentFactory EmbeddedBiometricPrompt.EmbeddedContentFactory: The factory to use to create the content view.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setExistingAuthSessionId

fun setExistingAuthSessionId(authSessionId: Long): EmbeddedBiometricPrompt.Builder

Optional: Sets the id for an existing authentication session.

Parameters
authSessionId Long: The id for an existing authentication session.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setLogoBitmap

fun setLogoBitmap(logoBitmap: Bitmap): EmbeddedBiometricPrompt.Builder

Optional: Sets the bitmap drawable of the logo that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

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 credential page.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setLogoDescription

fun setLogoDescription(logoDescription: String): EmbeddedBiometricPrompt.Builder

Optional: Sets logo description text that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

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 credential page.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setLogoRes

fun setLogoRes(logoRes: Int): EmbeddedBiometricPrompt.Builder

Optional: Sets the drawable resource of the logo that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

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 credential page.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setNegativeButton

fun setNegativeButton(
    text: CharSequence,
    executor: Executor,
    listener: DialogInterface.OnClickListener
): EmbeddedBiometricPrompt.Builder

Optional: 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.

If not provided and no fallback is added through addFallbackOption(CharSequence,int,Executor,DialogInterface.OnClickListener) (API 36.1 and later), the option to use device credential will be shown as the negative button if allowed in setAllowedAuthenticators(int). If credential is not allowed, "Cancel" will be shown as the negative button.

In API 36 and earlier, this setting is required. Note that this setting is not required, and in fact is explicitly disallowed, if device credential authentication is enabled via setAllowedAuthenticators(int). To use credential authentication and provide custom behavior, use addFallbackOption(CharSequence,int,Executor,DialogInterface.OnClickListener)

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
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setNextTranslationOffset

fun setNextTranslationOffset(nextTranslationOffset: Int): EmbeddedBiometricPrompt.Builder

Optional: Sets the ending target layout translation offset in pixels (px) for the disappear (exit) animation of the biometric prompt.

When the prompt is dismissed, it animates from its resting position to this target layout offset.

In portrait mode, the offset is applied vertically along the Y-axis (vertical slide).

In landscape mode, the offset is applied horizontally along the X-axis (horizontal slide), relative to the display boundaries based on the current screen rotation (e.g. 90 or 270 degrees).

This absolute pixel value can be used to synchronize the exit of the prompt with the entry animation of a subsequent screen in the client application.

Parameters
nextTranslationOffset Int: The ending target translation offset in pixels (px).
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setPreviousTranslationOffset

fun setPreviousTranslationOffset(previousTranslationOffset: Int): EmbeddedBiometricPrompt.Builder

Optional: Sets the starting layout translation offset in pixels (px) for the appear (entry) animation of the biometric prompt.

When the prompt is shown, its initial position is translated by this offset relative to its final resting position, and it animates to its final centered position (0 translation). If not set, or set to -1, a default system vertical translation is used.

In portrait mode, the offset is applied vertically along the Y-axis.

This absolute pixel value can be used to synchronize the entry of the prompt with the exit animation of a preceding screen in the client application.

Parameters
previousTranslationOffset Int: The starting translation offset in pixels (px).
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setSubtitle

fun setSubtitle(subtitle: CharSequence): EmbeddedBiometricPrompt.Builder

Optional: Sets a subtitle that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

Parameters
subtitle CharSequence: The subtitle to display on the credential page.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.

setTitle

fun setTitle(title: CharSequence): EmbeddedBiometricPrompt.Builder

Required: Sets the title that will be shown on the device credential fallback page (when the user is authenticating with PIN/pattern/password).

Parameters
title CharSequence: The title to display on the credential page.
This value cannot be null.
Return
EmbeddedBiometricPrompt.Builder This builder.
This value cannot be null.