Class2BiometricAuthExtensionsKt
public final class Class2BiometricAuthExtensionsKt
Summary
Public methods |
|
|---|---|
static final @NonNull BiometricPrompt.AuthenticationResult |
authenticate(Shows an authentication prompt to the user. |
static final @NonNull BiometricPrompt.AuthenticationResult |
authenticateWithClass2Biometrics(Prompts the user to authenticate with a Class 2 biometric (e.g. fingerprint, face, or iris). |
static final @NonNull BiometricPrompt.AuthenticationResult |
authenticateWithClass2Biometrics(Prompts the user to authenticate with a Class 2 biometric (e.g. fingerprint, face, or iris). |
static final @NonNull <Error class: unknown class> |
startClass2BiometricAuthentication(Prompts the user to authenticate with a Class 2 biometric (e.g. fingerprint, face, or iris). |
static final @NonNull <Error class: unknown class> |
startClass2BiometricAuthentication(Prompts the user to authenticate with a Class 2 biometric (e.g. fingerprint, face, or iris). |
Public methods
authenticate
public static final @NonNull BiometricPrompt.AuthenticationResult authenticate(
@NonNull <Error class: unknown class> receiver,
@NonNull <Error class: unknown class> host
)
Shows an authentication prompt to the user.
import androidx.biometric.BiometricPrompt import androidx.biometric.auth.AuthPromptErrorException import androidx.biometric.auth.AuthPromptFailureException import androidx.biometric.auth.AuthPromptHost import androidx.biometric.auth.Class2BiometricAuthPrompt 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 <Error class: unknown class> host |
A wrapper for the component that will host the prompt. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.AuthenticationResult |
|
| 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 | |
|---|---|
Class2BiometricAuthPrompt.authenticate |
(AuthPromptHost, AuthPromptCallback) |
authenticateWithClass2Biometrics
public static final @NonNull BiometricPrompt.AuthenticationResult authenticateWithClass2Biometrics(
@NonNull Fragment receiver,
@NonNull CharSequence title,
@NonNull CharSequence negativeButtonText,
CharSequence subtitle,
CharSequence description,
boolean confirmationRequired
)
Prompts the user to authenticate with a Class 2 biometric (e.g. fingerprint, face, or iris).
Note that Class 3 biometrics are guaranteed to meet the requirements for Class 2 and thus will also be accepted.
| Parameters | |
|---|---|
@NonNull CharSequence title |
The title to be displayed on the prompt. |
@NonNull CharSequence negativeButtonText |
The label for the negative button on the prompt. |
CharSequence subtitle |
An optional subtitle to be displayed on the prompt. |
CharSequence description |
An optional description to be displayed on the prompt. |
boolean confirmationRequired |
Whether user confirmation should be required for passive biometrics. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.AuthenticationResult |
|
| 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 | |
|---|---|
Class2BiometricAuthPrompt |
authenticateWithClass2Biometrics
public static final @NonNull BiometricPrompt.AuthenticationResult authenticateWithClass2Biometrics(
@NonNull FragmentActivity receiver,
@NonNull CharSequence title,
@NonNull CharSequence negativeButtonText,
CharSequence subtitle,
CharSequence description,
boolean confirmationRequired
)
Prompts the user to authenticate with a Class 2 biometric (e.g. fingerprint, face, or iris).
Note that Class 3 biometrics are guaranteed to meet the requirements for Class 2 and thus will also be accepted.
| Parameters | |
|---|---|
@NonNull CharSequence title |
The title to be displayed on the prompt. |
@NonNull CharSequence negativeButtonText |
The label for the negative button on the prompt. |
CharSequence subtitle |
An optional subtitle to be displayed on the prompt. |
CharSequence description |
An optional description to be displayed on the prompt. |
boolean confirmationRequired |
Whether user confirmation should be required for passive biometrics. |
| Returns | |
|---|---|
@NonNull BiometricPrompt.AuthenticationResult |
|
| 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 | |
|---|---|
Class2BiometricAuthPrompt |
startClass2BiometricAuthentication
public static final @NonNull <Error class: unknown class> startClass2BiometricAuthentication(
@NonNull Fragment receiver,
@NonNull CharSequence title,
@NonNull CharSequence negativeButtonText,
CharSequence subtitle,
CharSequence description,
boolean confirmationRequired,
Executor executor,
@NonNull <Error class: unknown class> callback
)
Prompts the user to authenticate with a Class 2 biometric (e.g. fingerprint, face, or iris).
Note that Class 3 biometrics are guaranteed to meet the requirements for Class 2 and thus will also be accepted.
| Parameters | |
|---|---|
@NonNull CharSequence title |
The title to be displayed on the prompt. |
@NonNull CharSequence negativeButtonText |
The label for the negative button on the prompt. |
CharSequence subtitle |
An optional subtitle to be displayed on the prompt. |
CharSequence description |
An optional description to be displayed on the prompt. |
boolean confirmationRequired |
Whether user confirmation should be required for passive biometrics. |
Executor executor |
An executor for |
@NonNull <Error class: unknown class> callback |
The object that will receive and process authentication events. |
| Returns | |
|---|---|
@NonNull <Error class: unknown class> |
An AuthPrompt handle to the shown prompt. |
| See also | |
|---|---|
Class2BiometricAuthPrompt |
startClass2BiometricAuthentication
public static final @NonNull <Error class: unknown class> startClass2BiometricAuthentication(
@NonNull FragmentActivity receiver,
@NonNull CharSequence title,
@NonNull CharSequence negativeButtonText,
CharSequence subtitle,
CharSequence description,
boolean confirmationRequired,
Executor executor,
@NonNull <Error class: unknown class> callback
)
Prompts the user to authenticate with a Class 2 biometric (e.g. fingerprint, face, or iris).
Note that Class 3 biometrics are guaranteed to meet the requirements for Class 2 and thus will also be accepted.
| Parameters | |
|---|---|
@NonNull CharSequence title |
The title to be displayed on the prompt. |
@NonNull CharSequence negativeButtonText |
The label for the negative button on the prompt. |
CharSequence subtitle |
An optional subtitle to be displayed on the prompt. |
CharSequence description |
An optional description to be displayed on the prompt. |
boolean confirmationRequired |
Whether user confirmation should be required for passive biometrics. |
Executor executor |
An executor for |
@NonNull <Error class: unknown class> callback |
The object that will receive and process authentication events. |
| Returns | |
|---|---|
@NonNull <Error class: unknown class> |
An AuthPrompt handle to the shown prompt. |
| See also | |
|---|---|
Class2BiometricAuthPrompt |