Vij*_*ole 7 android kotlin android-biometric-prompt android-biometric
我需要使用指纹和人脸身份验证来集成生物识别身份验证。指纹认证工作完美,但当我只设置人脸认证时,我从 BiometricManager.from(context) 方法得到生物识别未注册响应,如下所示,
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")
}
}
Run Code Online (Sandbox Code Playgroud)
Android 生物识别 API 仅适用于生物识别功能(面部、指纹、虹膜)与 Android 生物识别堆栈兼容的设备。我有一组支持人脸功能的设备,其中只有少数支持Android生物识别。
在查看了 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()
Run Code Online (Sandbox Code Playgroud)
通过它,即使仅设置了面部 ID 并且不支持当前回调,应用程序也会回退到设备 PIN 身份验证方法。
| 归档时间: |
|
| 查看次数: |
3416 次 |
| 最近记录: |