Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Face Authentication using androidx Biometric API in Android

I need to integrate Biometric authentication using Fingerprint and Face authentication. Fingerprint authentication works perfectly but when I set only Face authentication I am getting Biometric not enrolled response from BiometricManager.from(context) method as follows,

val biometricManager = BiometricManager.from(context)
    when(biometricManager.canAuthenticate()){
        BiometricManager.BIOMETRIC_SUCCESS ->{
            Log.e(TAG, "App can authenticate using biometrics.")
        }
        BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE ->{
            Log.d(TAG, "Hardware not available")
        }
        BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE ->{
            Log.d(TAG, "Biometric features are currently unavailable.")
        }
        BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED ->{
            Log.d(TAG, "The user hasn't associated any biometric credentials with their account.")
        }
        else ->{
            Log.d(TAG, "Nothing supported")
        }
    }
like image 641
Vijay Patole Avatar asked Aug 28 '20 07:08

Vijay Patole


2 Answers

Android Biometric APIs would only work on the devices which have their biometric features (face,fingerprint, iris) compatible with Android Biometric stack. I have a set of devices with Face feature support, among them only few support Android Biometrics.

like image 141
Shanker Avatar answered Sep 21 '22 21:09

Shanker


After looking at all the hurdles implementing the biometric for Android, I have chosen not to use BiometricManager.from(context) method to check if Biometric authentication is enabled, instead of that checked if KEYGUARD_SERVICE is enabled and used following prompt info

BiometricPrompt.PromptInfo.Builder().apply {
            setTitle(getString(R.string.title))
            setSubtitle(getString(R.string.sub_title))
            setConfirmationRequired(true)
            setDeviceCredentialAllowed(true)
        }.build()

through which even if only face ID is set and is not supporting the current callbacks, application fallbacks to devices PIN authentication method.

like image 23
Vijay Patole Avatar answered Sep 21 '22 21:09

Vijay Patole