У меня есть приложение, в котором, чтобы открыть приложение, пользователю необходимо ввести свой отпечаток пальца или использовать опцию PIN-кода (которую он ранее настроил в своем телефоне), как это предусмотрено в API биометрии.
Поэтому, когда пользователь аутентифицирует себя по отпечатку пальца, все работает нормально. Однако, когда пользователь проходит аутентификацию с помощью своего пин-кода, обратный вызов ошибки аутентификации вызывается с кодом ошибки 5, что не является нормальным поведением.
Я пытался проверить, почему это происходит, и я не могу понять.
Мой код выглядит следующим образом:
if (!hasEnrollments()) {
/*
* This means that a user that previously has enrolled
* biometrics, no longer have them
* we hence cannot let the user proceed until
* new enrolments are configured.
* We then show a dialog to the user explaining the situation
*/
biometricEnrolmentDialog()
return
}
_executor = ContextCompat.getMainExecutor(requireContext().applicationContext)
_biometricPrompt = BiometricPrompt(
this, _executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
Log.i("BIO_TEST", "Entered Auth Error")
Log.i("BIO_TEST", "ErCode: $errorCode errStr: $errString")
/* Error occurred while authenticating */
toast(getString(R.string.error_biometric_authentication_error, errString))
/* Close the app */
requireActivity().finish()
}
override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult
) {
super.onAuthenticationSucceeded(result)
Log.i("BIO_TEST", "Entered Auth Succeeded")
/* Biometric has succeeded */
viewModel.canNavigateToMainScreen.value = true
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
Log.i("BIO_TEST", "Entered Auth Failed")
/* Biometric has failed */
toast(getString(R.string.error_biometric_authentication_failed))
/* Close the app */
requireActivity().finish()
}
})
_promptInfo = BiometricPrompt.PromptInfo
.Builder()
.setTitle(getString(R.string.text_title_alert_biometric_authentication))
.setSubtitle(getString(R.string.text_title_alert_biometric_authentication_message))
.setDeviceCredentialAllowed(true)
.setConfirmationRequired(false)
.build()
/* Prompts the user for biometric authentication */
_biometricPrompt.authenticate(_promptInfo)
Когда я использую отпечаток пальца для аутентификации, вызывается обратный вызов успешной аутентификации, и приложение работает нормально. Но когда я вместо этого использую пин-код, он переходит в обратный вызов ошибки аутентификации и закрывает мое приложение.
Я использую API биометрии androidx.biometric:biometric:1.0.1
Может кто-нибудь, пожалуйста, помогите мне?