问题
I'm using BiometricPrompt from androidx.biometric:biometric:1.0.0-beta02
for the authenticate process.
But i face very strange problem.
First time i call biometricsPromt.authenticate()
everything works fine, the library shows me the screen depending what security method is set(pattern,fingerprint, password and etc…) then the callback is called and everything is good.
The problem is when i call biometricsPromt.authenticate()
for the second time i got the error:
E/DeviceCredentialHandler: onCreate: Executor and/or callback was null!
I'm passing executor and callback of course -> they are not null
Does anyone face the same problem or have some idea what can be the problem?
This is how i'm creating the BiometricPromt
`
companion object {
private val executor: Executor by lazy {
Executors.newSingleThreadExecutor()
}
fun showBiometricsPrompt(
activity: FragmentActivity,
callback: BiometricPrompt.AuthenticationCallback
): BiometricPrompt {
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle(activity.getString(R.string.title_authentication))
.setDescription(activity.getString(R.string.msg_authenticate_first))
.setDeviceCredentialAllowed(true)
.build()
val biometricPrompt =
BiometricPrompt(
activity,
executor, callback
)
biometricPrompt.authenticate(promptInfo)
return biometricPrompt
}
`
And here is how i called:
`
BiometricsHelper.showBiometricsPrompt(
this,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
showToastMsg(errString.toString())
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
}
})
`
回答1:
Here's a work around this problem, but not a complete fix.
You need to call recreate()
after you finish doing whatever you set out to do after the authentication.
This will restart the activity and allow the biometric prompt to be shown again.
回答2:
What device are you testing on? Can you file a bug on the public issuetracker here with both
- adb bugreport foo.zip
- ideally a .zip of a sample app that reproduces the issue?
回答3:
It seems it is related to this line: .setDeviceCredentialAllowed(true)
If I change that to false, it works every time without re-creating the activity
来源:https://stackoverflow.com/questions/58286606/biometricprompt-executor-and-or-callback-was-null