In Android BiometricPrompt prompt has replaced the deprecated FingerprintManager.
FingerPrintManager has two functions hasEnrolledFingerprints()
and isHardwareDetected()
to check if the device supports fingerprints and if the user has enrolled any fingerprint authentication.
With the new BiometricPrompt it seems there are no functions to check this without trying to prompt the BiometricPrompt. There is a BiometricPrompt.AuthenticationCallback.onAuthenticationError(
that is called with an error code indicating if the device supports biometric and if the user has biometric authentication enrolled.
So I can only get this information if I try to authenticate from the user. Is there a way to check without trying to prompt the authentication to check if the device supports biometrics and the user has enrolled them?
AndroidX Biometric beta01 added BiometricManager.canAuthenticate(int)
(formerly BiometricManager.canAuthenticate()
)
Use the following dependency line in your app module's build.gradle file.
implementation 'androidx.biometric:biometric:1.1.0'
Then you can do the following to check if any biometrics are ready for use on the device.
BiometricManager.from(context).canAuthenticate(int) == BiometricManager.BIOMETRIC_SUCCESS
On Android 6 to 9 this only supports fingerprints. On 10 and above it will support any biometric (eg. face, iris).