我已经实现了生物识别身份验证,但它在我的三星(Android 10)设备上运行良好,但在一个毛绒和 MI 设备上却无法运行。
在小米(Android 10)和一个毛绒(Android 10)设备中,它只显示指纹提示,但不显示人脸认证选项
我在两个设备设置中都设置了我的面部 ID,但它不起作用。仅适用于三星设备。
我用过下面的代码
executor = ContextCompat.getMainExecutor(this)
biometricPrompt = BiometricPrompt(this, executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int,
errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
Toast.makeText(applicationContext,
"Authentication error: $errString", Toast.LENGTH_SHORT)
.show()
}
override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
Toast.makeText(applicationContext,
"Authentication succeeded!", Toast.LENGTH_SHORT)
.show()
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
Toast.makeText(applicationContext, "Authentication failed",
Toast.LENGTH_SHORT)
.show()
}
})
promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
.setConfirmationRequired(true).
setNegativeButtonText("login")
.build()
val biometricLoginButton =
findViewById<TextView>(R.id.tvClick)
biometricLoginButton.setOnClickListener {
biometricPrompt.authenticate(promptInfo)
}