我正在开发一个Android应用程序,需要指纹才能打开活动。我刚刚注意到,当我使用指纹解锁手机时,在我的应用程序中尝试扫描指纹的次数只变成了 4 次。
例如:
手机已锁定
使用指纹解锁手机
打开我的指纹应用程序
无法尝试扫描指纹超过 4 次
另一个场景:
指纹应用程序已打开
只接受5次尝试,应用程序将不再尝试扫描指纹
等待一段时间,同样,一段时间内只接受5次尝试
有解决方法吗?
我做了一些研究,找到了Android 6.0兼容性定义文档。
这已在指纹传感器部分中说明:
具有安全锁屏的设备实现应包含指纹传感器。如果一个设备 实现包括指纹传感器并为第三方开发者提供相应的API, 它:
在指纹 5 次错误尝试后,必须限制尝试频率至少 30 秒 验证。
所以..我想目前没有解决方法。
在搜索我遇到的相同问题时遇到了这个 stackoverflow。
无论如何,使用最新的 API BiometricPrompt,我们现在可以通过覆盖 AuthenticationCallback 来自定义行为
BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(
errorCode: Int,
errString: CharSequence
) {
super.onAuthenticationError(errorCode, errString)
}
override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult
) {
super.onAuthenticationSucceeded(result)
}
// called when an attempt to authenticate with biometrics fails
// i.e. invalid fingerprint
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
// keep track of a counter here and decide when to dismiss the dialog
biometricPrompt?.cancelAuthentication()
}
}