Class2BiometricAuthExtensionsKt

public final class Class2BiometricAuthExtensionsKt


Summary

Public methods

static final @NonNull BiometricPrompt.AuthenticationResult

Shows an authentication prompt to the user.

static final @NonNull BiometricPrompt.AuthenticationResult
Class2BiometricAuthExtensionsKt.authenticateWithClass2Biometrics(
    @NonNull FragmentActivity receiver,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired
)

Prompts the user to authenticate with a Class 2 biometric (e.g.

static final @NonNull BiometricPrompt.AuthenticationResult
Class2BiometricAuthExtensionsKt.authenticateWithClass2Biometrics(
    @NonNull Fragment receiver,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired
)

Prompts the user to authenticate with a Class 2 biometric (e.g.

static final @NonNull AuthPrompt
Class2BiometricAuthExtensionsKt.startClass2BiometricAuthentication(
    @NonNull FragmentActivity receiver,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired,
    @Nullable Executor executor,
    @NonNull AuthPromptCallback callback
)

Prompts the user to authenticate with a Class 2 biometric (e.g.

static final @NonNull AuthPrompt
Class2BiometricAuthExtensionsKt.startClass2BiometricAuthentication(
    @NonNull Fragment receiver,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired,
    @Nullable Executor executor,
    @NonNull AuthPromptCallback callback
)

Prompts the user to authenticate with a Class 2 biometric (e.g.

Public methods

Class2BiometricAuthExtensionsKt.authenticate

@NonNull
public static final BiometricPrompt.AuthenticationResult Class2BiometricAuthExtensionsKt.authenticate(
    @NonNull Class2BiometricAuthPrompt receiver,
    @NonNull AuthPromptHost host
)

Shows an authentication prompt to the user.

import androidx.biometric.auth.AuthPromptHost
import androidx.biometric.auth.authenticate

val payload = "A message to encrypt".toByteArray(Charset.defaultCharset())

// Construct AuthPrompt with localized Strings to be displayed to UI.
val authPrompt = Class2BiometricAuthPrompt.Builder(title, negativeButtonText).apply {
    setSubtitle(subtitle)
    setDescription(description)
    setConfirmationRequired(true)
}.build()

try {
    val authResult = authPrompt.authenticate(AuthPromptHost(this))

    // Encrypt a payload using the result of crypto-based auth.
    val encryptedPayload = authResult.cryptoObject?.cipher?.doFinal(payload)

    // Use the encrypted payload somewhere interesting.
    sendEncryptedPayload(encryptedPayload)
} catch (e: AuthPromptErrorException) {
    // Handle irrecoverable error during authentication.
    // Possible values for AuthPromptErrorException.errorCode are listed in the @IntDef,
    // androidx.biometric.BiometricPrompt.AuthenticationError.
} catch (e: AuthPromptFailureException) {
    // Handle auth failure due biometric credentials being rejected.
}
Parameters
@NonNull AuthPromptHost host

A wrapper for the component that will host the prompt.

Returns
BiometricPrompt.AuthenticationResult

AuthenticationResult for a successful authentication.

Throws
androidx.biometric.auth.AuthPromptErrorException

when an unrecoverable error has been encountered and authentication has stopped.

androidx.biometric.auth.AuthPromptFailureException

when an authentication attempt by the user has been rejected.

See also
authenticate

(AuthPromptHost, AuthPromptCallback)

Class2BiometricAuthExtensionsKt.authenticateWithClass2Biometrics

@NonNull
public static final BiometricPrompt.AuthenticationResult Class2BiometricAuthExtensionsKt.authenticateWithClass2Biometrics(
    @NonNull FragmentActivity receiver,
    @NonNull CharSequence title,
    @NonNull CharSequence negativeButtonText,
    @Nullable CharSequence subtitle,
    @Nullable CharSequence description,
    boolean confirmationRequired
)

Pro