You should migrate from using FingerprintManager
to BiometricPrompt
. There is a blog that shows just how to do so.
Unlike with the FingerprintManager
API, you can check whether a device supports biometric authentication with a single method call: BiometricManager.from(context).canAuthenticate()
. This singular method call checks whether there is biometric hardware available on the device, whether the user has enrolled templates, and whether the user has enabled biometric authentication. If all three are not true, then the biometric prompt cannot be shown. It's a highly convenient method that handles all the complexities for you.
// Callback for the "authenticate" button in your app's UI.
override fun onClick(view: View) {
val promptInfo = createPromptInfo()
if (BiometricManager.from(context)
.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
biometricPrompt.authenticate(promptInfo, cryptoObject)
} else {
loginWithPassword()
}
}