I'm implementing the latest Biometric prompt in my app and made the Confirmation required true. While doing facial recognition it prompts for user confirmation on successful face verification. If the user clicks on the cancel in the confirmation prompt means I need to execute my function but I don't see any callbacks for that canceled event to override to execute my function. Please help me with this.
That cancel event does not listen in the AuthenticationCallBack. And, I don't see any suggestions or solutions in android docs or forums regarding this issue.
fun initBiometricPrompt(
activity: AppCompatActivity,
listener: BiometricAuthListener
): BiometricPrompt {
val callback = object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
listener.onBiometricAuthenticationError(errorCode, errString.toString())
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
Timber.tag("BioMetricAuthentication").e("Authentication failed for an unknown reason")
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
listener.onBiometricAuthenticationSuccess(result)
}
}
return BiometricPrompt(activity, getMainExecutor(activity), callback)
}
fun showBiometricPrompt(
@StringRes
title: Int = R.string.unlock_app
showSubtitle: Boolean = true,
activity: AppCompatActivity,
listener: BiometricAuthListener,
allowDeviceCredential: Boolean = true
) {
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle(activity.getString(title))
.setConfirmationRequired(true)
.setSubtitle((activity.getString(R.string.confirm_your_screen_lock)))
.apply {
if (allowDeviceCredential) {
setDeviceCredentialAllowed(allowDeviceCredential)
} else {
setNegativeButtonText(activity.getString(R.string.cancel))
}
}.build()
val biometricPrompt = initBiometricPrompt(activity, listener)
biometricPrompt.authenticate(promptInfo)
}
