简体   繁体   English

在 Android 中使用 androidx Biometric API 进行人脸认证

[英]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'”。

  1. Samsung device doesn't support face recognition as it doesn't have a 3D face unlock refer here .三星设备不支持人脸识别,因为它没有 3D 人脸解锁, 请参阅此处 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.但它确实支持使用生物识别管理器 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.真人脸解锁仅适用于 Pixel 4(这是基于我的测试,不确定其他设备是否支持,但我测试过一流设备是三星,包括 Note 系列和 Galaxy 系列以及摩托罗拉系列)我只能使用面部在 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.到目前为止,很少有应用程序支持面部解锁,因为大多数 Android 基础设备不是来自谷歌,而且基于 3d 的解锁在制造方面不可用。

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.

相关问题 如何使用 Biometric api 进行人脸认证 - How to use face authentication using Biometric api 如果仅安装了面部作为生物特征,则使用 AndroidX.Biometric 的 KeyGeneration 会失败 - KeyGeneration using AndroidX.Biometric fails if only face as biometric is installed 如何在我的旧 Android 项目中添加生物识别支持 ​​API (AndroidX) - How to add Biometric support API (AndroidX) in my Old Android Project "哪款 Android 设备具有 BIOMETRIC_STRONG(第 3 类)人脸身份验证?" - Which Android device has BIOMETRIC_STRONG (Class 3) face authentication? 使用生物识别 androidx 库时崩溃 - Crash using biometric androidx library 使用生物识别 androidX 库 1.1.0 崩溃 - Crash using biometric androidX library 1.1.0 Android 生物识别 API 问题 - Android Biometric API Issue 使用设备凭据时,AuthenticationCallback 中的 Android 生物识别身份验证无效变量 - Android biometric authentication invalid variables in AuthenticationCallback when using device credential 无法使用生物识别管理器打开人脸识别 - Unable to open face recoginition using biometric manager 如何使用生物特征 api 检测 android 中是否通过了生物特征验证 - How do you detect if biometric auth has been passed in android , using biometric api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM