1 回答
TA贡献1883条经验 获得超3个赞
问题终于解决了
BiometricManagerandroidx 库中错过了课程
androidx.biometric:biometric:1.0.0-alpha04
将库版本更新为
androidx.biometric:biometric:1.0.0-beta01
现在您可以导入androidx.biometric.BiometricManager
您可以通过以下代码检查生物识别硬件的可用性并已注册生物识别:
object BiometricUtil {
fun isHardwareAvailable(context: Context): Boolean{
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
val bm = BiometricManager.from(context)
val canAuthenticate = bm.canAuthenticate()
!(canAuthenticate == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE || canAuthenticate == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE)
} else {
false
}
}
fun hasBiometricEnrolled(context: Context): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
val bm = BiometricManager.from(context)
val canAuthenticate = bm.canAuthenticate()
(canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS)
} else {
false
}
}
}
添加回答
举报