I'm implementing biometrics and I would like to be able to fall back to using PIN if user doesn't want/have biometrics.
The issue is that when the user selects "Use PIN", enters their pin, and authenticates two different callbacks get triggered:
The first: onAuthenticationSucceeded
which is expected. The second: onAuthenticationError
with BiometricConstants.ERROR_USER_CANCELED
.
Why does entering a PIN instead of biometric trigger ERROR_USER_CANCELED? I had handled this error by finishing my Activity which is not what I want in this flow. I did so because when the user taps outside of the dialog I want to close the app and this same error triggers in that case (despite this fix).
Is there a way to differentiate between cancelling the dialog intentionally (through the back button or by tapping outside the dialog) and entering a PIN?
Here is my PromptInfo
:
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle(getString(R.string.lock_title))
.setSubtitle(getString(R.string.lock_summary))
.setConfirmationRequired(false)
.setDeviceCredentialAllowed(true)
.build()
Testing on a Pixel 2 with Android 10. Using version "androidx.biometric:biometric:1.0.1"
. Thank you!