我正在使用 BiometricPrompt 类实现生物识别身份验证。
在调用方法之前如何检查硬件是否可用BiometricPrompt#authenticate
?
如何查看是否已登记生物识别?
如何调用BiometricManager#canAuthenticate
方法?我无法在 kotlin 中为 BiometricManager 类创建对象
我当前的实现如下。
val executor = Executors.newSingleThreadExecutor()
val biometricPrompt = BiometricPrompt(this, executor, object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
Log.d("BIOMETRIC", "$errString $errorCode")
if (BiometricPrompt.ERROR_HW_NOT_PRESENT == errorCode || BiometricPrompt.ERROR_NO_BIOMETRICS == errorCode)
PreferenceHandler.setBiometricAvailable(this@LockActivity, false)
else
PreferenceHandler.setBiometricAvailable(this@LockActivity, true)
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
Log.d("BIOMETRIC", "FAILED")
}
})
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("App title")
.setSubtitle("")
.setDescription("Identify yourself by Biometrics")
.setNegativeButtonText("Use Password")
.build()
biometricPrompt.authenticate(promptInfo)
白板的微信
相关分类