Determine if biometric hardware is present and the user has enrolled biometrics on Android P
Solution 1:
Google finally solved this problem with Android Q
The android.hardware.biometrics.BiometricManager#canAuthenticate() method can be used to determine if biometrics can be used.
The method can be used to determine if biometric hardware is present and if the user is enrolled or not.
Returns BIOMETRIC_ERROR_NONE_ENROLLED if the user does not have any enrolled, or BIOMETRIC_ERROR_HW_UNAVAILABLE if none are currently supported/enabled. Returns BIOMETRIC_SUCCESS if a biometric can currently be used (enrolled and available).
Hopefully this is added to the androidx.biometric:biometric
library, so it can be used on all devices.
Until then the solution by @algrid works to determine biometrics enrollment.
And the following can be used to determine, if a fingerprint reader is present.
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
context.packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)
Solution 2:
AndroidX biometric library started providing this kind of information from version 1.0.0-beta01
(androidx.biometric:biometric:1.0.0-beta01
)
BiometricManager.from(context).canAuthenticate()
Which returns one of
- BIOMETRIC_SUCCESS
- BIOMETRIC_ERROR_HW_UNAVAILABLE
- BIOMETRIC_ERROR_NONE_ENROLLED
- BIOMETRIC_ERROR_NO_HARDWARE
See changelog: https://developer.android.com/jetpack/androidx/releases/biometric#1.0.0-beta01