6

I am currently developing a Biometrics library for a project and can't seem to make facial recognition work.

The BiometricManager works correctly for fingerprints in all devices i've tried, however it doesn't detect any enrolled face biometrics for my Huawei P30 ELE-L29 (EMUI version 10.0.0 - Android version 10) and return BIOMETRIC_ERROR_NONE_ENROLLED when I call BiometricManager#canAuthenticate(). This is the only device with API version 29 I have available since Android Studio emulator doesn't have facial recognition implemented and other emulators (Bluestacks, Nox, etc.) can't be configured to run on Android 10 on my macbook.

I would appreciate any light on the subject since facial recognition is new for native android and I couldn't find any similar issue out there. I'm not sure if it's a problem with this particular phone or if I have an error in my code.

My minSdkVersion is 23 (Android 6.0 Marshmallow) and my targetSdkVersion is 29 (Android 10 Q).

My (partial) implementation:

fun isBiometricsSupported(@NonNull context: Context): Boolean {
        val biometricManager = BiometricManager.from(context)
        var isBiometricsSupported = false

        when (biometricManager.canAuthenticate()) {
            BiometricManager.BIOMETRIC_SUCCESS -> {
                isBiometricsSupported = true
            }
            BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE -> {
                Log.println(Log.INFO, "a", "Logger: BIOMETRIC_ERROR_NO_HARDWARE")
            }
            BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> {
                Log.println(Log.INFO, "a", "Logger: BIOMETRIC_ERROR_NONE_ENROLLED")
                //It always goes here if I don't have any fingerprints enrolled,
                //ignoring all other biometric data I may have.
            }
            BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE -> {
                Log.println(Log.ERROR, "a", "Logger: BIOMETRIC_ERROR_HW_UNAVAILABLE")
            }
        }
        return isBiometricsSupported
    }
Horkur
  • 91
  • 1
  • 3
  • Are you perhaps passing a CryptoObject into the BiometricPrompt when calling authenticate? For example, biometricPrompt.authenticate(promptInfo, cryptoObject). If you are doing this, also check whether you are setting setUserAuthenticationRequired() and setInvalidatedByBiometricEnrollment(true) when setting up the CryptoObject (The latter is true by default). I found that when I did this, it only accepts fingerprints and not facial recognition. – Yusuf Isaacs Feb 14 '20 at 08:45

1 Answers1

0

From your error, there are no biometric templates enrolled on the device. You must first register your biometric template in Settings before you can use biometrics in any other app. You can usually do this under "Security". Also one way to check if a biometric template is registered is this: if you turn off your phone, are you able to unlock it with biometrics (fingerprint or face, etc.)?

Isai Damier
  • 976
  • 6
  • 8
  • Hi Isai, I'm sorry for not being clear enough, but I do have face recognition enabled and with enrolled credentials (as you say, I can unlock the phone using face recognition), however the BiometricManager doesn't seem to see them. – Horkur Jan 14 '20 at 15:03
  • Is this your device? https://www.amazon.com/ELE-L29-Factory-Unlocked-Smartphone-International/dp/B07Q2X19LG I took a quick look and it seems the OS version 10 is not available in the US where I am based. I was hoping to be able to help you troubleshoot – Isai Damier Jan 14 '20 at 17:42