以编程方式测试设备指纹是否正常工作

问题描述 投票:0回答:2

是否可以通过程序测试手机的指纹传感器是否正常工作?我希望能够自动执行测试,而无需注册我的指纹,然后尝试使用它登录以查看传感器是否正常工作。希望这对某人有意义!

android fingerprint android-fingerprint-api
2个回答
0
投票

SDK 23 +

fun isHardwareSupported(context: Context): Boolean {
   val fingerprintManager = FingerprintManagerCompat.from(context)
   return fingerprintManager.isHardwareDetected
}

SDK 28+

fun isHardwareSupported(context: Context): Boolean {
  val pm = context.packageManager
  return pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)
}

0
投票

另一种替代方法是使用BiometricManager androidx库

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

fun isHardwareSupported(context: Context): Boolean {
    return BiometricManager.from(context).canAuthenticate() != BIOMETRIC_ERROR_HW_UNAVAILABLE)
}

如果用户没有注册,则返回BIOMETRIC_ERROR_NONE_ENROLLED,如果当前不支持/启用,则返回BIOMETRIC_ERROR_HW_UNAVAILABLE。如果当前可以使用生物特征(已注册并可用),则返回BIOMETRIC_SUCCESS。值是BIOMETRIC_SUCCESS,BIOMETRIC_ERROR_HW_UNAVAILABLE,BIOMETRIC_ERROR_NONE_ENROLLED或BIOMETRIC_ERROR_NO_HARDWARE

© www.soinside.com 2019 - 2024. All rights reserved.