Component - Biometric authentication
This UI component allows users to authenticate themselves using their fingerprint or face recognition. It shows a prompt asking the user to verify their identity biometrically, enhancing security and convenience.
This UI component allows users to authenticate themselves using their fingerprint or face recognition. It shows a prompt asking the user to verify their identity biometrically, enhancing security and convenience.
BiometricPromptDialog ├── TitleTextView ├── SubtitleTextView ├── DescriptionTextView ├── BiometricIconView └── CancelButton
BiometricPrompt in an Android app?BiometricPrompt is a system API that shows a standard biometric authentication dialog to the user.BiometricPrompt instance in Kotlin?BiometricPrompt is created by calling its constructor with context, executor, and callback.val callback = object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
println("Success")
}
override fun onAuthenticationFailed() {
println("Failed")
}
}
// Assume biometricPrompt is initialized and authenticate() is called with this callbackonAuthenticationSucceeded method runs when biometric authentication is successful.onAuthenticationSucceeded, it prints "Success". So on success, "Success" is printed.val biometricPrompt = BiometricPrompt(this, executor, callback) biometricPrompt.authenticate(promptInfo) // callback object missing override for onAuthenticationError
onAuthenticationError is recommended but not mandatory; missing it won't crash or prevent compilation.onAuthenticationError, errors won't be handled gracefully, but authentication still runs.val biometricManager = BiometricManager.from(this)
val canAuthenticate = biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG or BiometricManager.Authenticators.DEVICE_CREDENTIAL)
if (/* condition here */) {
biometricPrompt.authenticate(promptInfo)
}canAuthenticate returns BIOMETRIC_SUCCESS if biometrics are available and enrolled.canAuthenticate == BIOMETRIC_SUCCESS should the app show the biometric prompt.Pass the test and this pattern moves unknown