为了解决这个问题,需要在使用BiometricPrompt进行身份验证时,显式地禁用设备凭据。以下是一个示例:
private fun showBiometricPrompt(context: Context) {
val executor = ContextCompat.getMainExecutor(context)
val biometricPrompt = BiometricPrompt(context, executor, object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
// Handle authentication successful.
}
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
// Handle authentication error.
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
// Handle authentication failed.
}
})
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Authentication Title")
.setSubtitle("Authentication Subtitle")
.setDescription("Authentication Description")
.setDeviceCredentialAllowed(false) // Disable device credential.
.build()
biometricPrompt.authenticate(promptInfo)
}