确定是否存在生物识别硬件以及用户是否已在Android P上注册了生物识别 [英] Determine if biometric hardware is present and the user has enrolled biometrics on Android P

查看:310
本文介绍了确定是否存在生物识别硬件以及用户是否已在Android P上注册了生物识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求显示某些UI元素,具体取决于生物识别硬件的存在.对于Android 23-27,我使用FingerprintManager#isHardwareDetected()FingerprintManager#hasEnrolledFingerprints().两者均已在Android 28中弃用.

I'm asked to show certain UI elements depending on the presence of biometric hardware. For Android 23-27 I use FingerprintManager#isHardwareDetected() and FingerprintManager#hasEnrolledFingerprints(). Both of which are deprecated in Android 28.

我知道我可以通过使用BiometricPrompt#authenticate(...)并在BiometricPrompt.AuthenticationCallback#onAuthenticationError(int errorCode, ...)方法中接收BiometricPrompt#BIOMETRIC_ERROR_HW_NOT_PRESENTBiometricPrompt#BIOMETRIC_ERROR_NO_BIOMETRICS来获取此信息.但这会导致BiometricPrompt显示在支撑设备上,这是不希望的.使用CancellationSignal似乎也不是解决方案,因为我不知道何时取消提示.

I understand that I can get this information by using BiometricPrompt#authenticate(...) and receiving either BiometricPrompt#BIOMETRIC_ERROR_HW_NOT_PRESENT or BiometricPrompt#BIOMETRIC_ERROR_NO_BIOMETRICS in the BiometricPrompt.AuthenticationCallback#onAuthenticationError(int errorCode, ...) method. But this would lead to the BiometricPrompt being shown on supporting devices, which is undesirable. Using the CancellationSignal doesn't seem to be a solution either, since I wouldn't know when to cancel the prompt.

有什么方法可以检测生物识别硬件的存在和用户注册吗?

Is there any way to detect biometric hardware presence and user enrolment?

推荐答案

Google终于用Android Q解决了这个问题

Google finally solved this problem with Android Q

android.hardware.biometrics.BiometricManager#canAuthenticate ()方法可用于确定是否可以使用生物识别技术.

The android.hardware.biometrics.BiometricManager#canAuthenticate() method can be used to determine if biometrics can be used.

该方法可用于确定是否存在生物识别硬件以及是否已注册用户.

The method can be used to determine if biometric hardware is present and if the user is enrolled or not.

如果用户没有注册,则返回BIOMETRIC_ERROR_NONE_ENROLLED;如果当前不支持/启用任何用户,则返回BIOMETRIC_ERROR_HW_UNAVAILABLE.如果当前可以使用生物特征(已注册并可用),则返回BIOMETRIC_SUCCESS.

Returns BIOMETRIC_ERROR_NONE_ENROLLED if the user does not have any enrolled, or BIOMETRIC_ERROR_HW_UNAVAILABLE if none are currently supported/enabled. Returns BIOMETRIC_SUCCESS if a biometric can currently be used (enrolled and available).

希望这已添加到androidx.biometric:biometric库中,因此可以在所有设备上使用.

Hopefully this is added to the androidx.biometric:biometric library, so it can be used on all devices.

@algrid提出的解决方案,直到确定生物识别技术注册为止.

Until then the solution by @algrid works to determine biometrics enrollment.

以下内容可用于确定是否存在指纹读取器.

And the following can be used to determine, if a fingerprint reader is present.

Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
            context.packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)

这篇关于确定是否存在生物识别硬件以及用户是否已在Android P上注册了生物识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆