1

I have an application where in order to open the app user needs to enter his fingerprint or use the PIN code option (which he had set up before in his phone) as provided in the Biometrics API.

So when the user authenticates himself with his fingerprint, it works fine. However, when the user authenticates using his pin code, the Authentication Error callback is being called with error code 5 which isn't a normal behavior.

I tried to check why this is happening and i can't figure it out.

My Code is a follows:

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)

When i use fingerprint to authenticate, the authentication succeeded callback is called and the application works just fine. But when i use pin instead, it goes into authentication error callback and close my app.

I am using the Biometrics API androidx.biometric:biometric:1.0.1

Can someone please help me ?

Mervin Hemaraju
  • 1,921
  • 2
  • 22
  • 71

0 Answers0