Face Authentication using androidx Biometric API in Android

雨燕双飞 提交于 2021-01-02 08:15:13

问题


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")
        }
    }

回答1:


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.




回答2:


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.




回答3:


Some of the facts I have found while I was working with it. This is based on Biometric API "implementation 'androidx.biometric:biometric:1.0.1'".

  1. Samsung device doesn't support face recognition as it doesn't have a 3D face unlock refer here. The issue is open on the Samsung side, as Samsung had face unlock developed by Samsung itself and not from google OS. But it does support fingerprint scans using biometric manager API.
  2. True face unlocks will only work with Pixel 4(This is based on my testing, not sure other device support but I have tested top-notch device is Samsung including the Note series and Galaxy series, and Motorola series) I only able to use face unlock in Pixel 4.
  3. Samsung is working on it and will be available soon(Not sure when).
  4. Very few application support face unlock as of now as most Android base devices are not from google and 3d based unlock is not available on the manufacturing side.

I have created reference POC for the community to help. The documentation hasn't provided good documentation on biometric change detection. This is pure kotlin code and also detects the biometric change and many functions such as does user enrolled in Bio, does device enroll in Bio, what type of biometric, is the user previously enrolled. Please take a look at this link.



来源:https://stackoverflow.com/questions/63629458/face-authentication-using-androidx-biometric-api-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!