[英]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,指纹认证工作完美,但当我只设置人脸认证时,我从 BiometricManager.from(context) 方法得到 Biometric not register 响应,如下所示,
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 Biometric APIs would only work on the devices which have their biometric features (face,fingerprint, iris) compatible with Android Biometric stack. Android 生物识别 API 仅适用于具有与 Android 生物识别堆栈兼容的生物识别特征(面部、指纹、虹膜)的设备。 I have a set of devices with Face feature support, among them only few support Android Biometrics.我有一组支持人脸功能的设备,其中只有少数支持 Android 生物识别。
I face the same issue while integrating it into my app When I use我在使用时将其集成到我的应用程序中时遇到了同样的问题
biometricManager.canAuthenticate(BIOMETRIC_STRONG)
to check biometric is available in the device it return BIOMETRIC_ERROR_NONE_ENROLLED and as soon as I change the authentication mode to BIOMETRIC_WEEK
it work well I test on Samsung S9 and a few Other devices.要检查设备中的生物识别是否可用,它会返回 BIOMETRIC_ERROR_NONE_ENROLLED,一旦我将身份验证模式更改为BIOMETRIC_WEEK
它就可以正常工作,我会在三星 S9 和一些其他设备上进行测试。 Currently is use this biometeric dependency hope it works for you目前正在使用这种生物识别依赖,希望它对你有用
implementation "androidx.biometric:biometric-ktx:1.2.0-alpha03"
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在查看了为 Android 实现生物识别的所有障碍之后,我选择不使用 BiometricManager.from(context) 方法来检查是否启用了生物识别身份验证,而不是检查是否启用了 KEYGUARD_SERVICE 并使用以下提示信息
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.即使只设置了人脸 ID 并且不支持当前回调,应用程序也会回退到设备 PIN 身份验证方法。
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'".这是基于生物识别 API“实现 'androidx.biometric:biometric:1.0.1'”。
I have created reference POC for the community to help.我已经为社区创建了参考 POC 以提供帮助。 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.这是纯 kotlin 代码,还检测生物特征变化和许多功能,例如用户是否在 Bio 中注册,设备是否在 Bio 中注册,用户以前注册的是什么类型的生物特征。 Please take a look at this link .请看一下这个链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.