Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if biometric hardware is present and the user has enrolled biometrics on Android P

I'm asked to show certain UI elements depending on the presence of biometric hardware. For Android 23-27 I use FingerprintManager#isHardwareDetected() and FingerprintManager#hasEnrolledFingerprints(). Both of which are deprecated in Android 28.

I understand that I can get this information by using BiometricPrompt#authenticate(...) and receiving either BiometricPrompt#BIOMETRIC_ERROR_HW_NOT_PRESENT or BiometricPrompt#BIOMETRIC_ERROR_NO_BIOMETRICS in the BiometricPrompt.AuthenticationCallback#onAuthenticationError(int errorCode, ...) method. But this would lead to the BiometricPrompt being shown on supporting devices, which is undesirable. Using the CancellationSignal doesn't seem to be a solution either, since I wouldn't know when to cancel the prompt.

Is there any way to detect biometric hardware presence and user enrolment?

like image 445
sirius Avatar asked Jun 21 '18 12:06

sirius


People also ask

What is biometric authentication in Android?

One method of protecting sensitive information or premium content within your app is to request biometric authentication, such as using face recognition or fingerprint recognition.

Does Android use biometrics?

The Android framework includes support for face and fingerprint biometric authentication. Android can be customized to support other biometric modalities (such as Iris). However, biometric integration will depend on biometric security, not modality.


1 Answers

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) 
like image 183
sirius Avatar answered Sep 26 '22 23:09

sirius