1 回答

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊
問(wèn)題終于解決了
BiometricManagerandroidx 庫(kù)中錯(cuò)過(guò)了課程
androidx.biometric:biometric:1.0.0-alpha04
將庫(kù)版本更新為
androidx.biometric:biometric:1.0.0-beta01
現(xiàn)在您可以導(dǎo)入androidx.biometric.BiometricManager
您可以通過(guò)以下代碼檢查生物識(shí)別硬件的可用性并已注冊(cè)生物識(shí)別:
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
}
}
}
添加回答
舉報(bào)