问题描述
我需要集成使用指纹和面部认证的生物识别认证.指纹身份验证可以正常工作,但是当我仅设置面部身份验证时,我无法从BiometricManager.from(context)方法获得生物识别,即未注册响应,如下所示,
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")
}
}
推荐答案
查看了实现Android生物识别的所有障碍之后,我选择不使用BiometricManager.from(context)方法来检查是否启用了生物识别,而不是根据提示信息检查是否启用了KEYGUARD_SERVICE并使用了它
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()
即使仅设置面部ID并且不支持当前的回调,应用程序也会回退到设备PIN身份验证方法.
through which even if only face ID is set and is not supporting the current callbacks, application fallbacks to devices PIN authentication method.
这篇关于在Android中使用androidx生物识别API进行人脸验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!