I am using FingerprintManager
to authenticate my app with fingerprint.
I have and android View
with the fingerprint ui and when the FingerprintManager.authenticate
callbacks are called I handle the callbacks in the view, e.g change fingerprint icon, error text etc.
Now in Android P, I have to use BiometricPrompt
, which is easy enough to use, but forces me to have an Activity
in order to work properly
Is there a way to make BiometricPrompt
work in a plain android view?
this is my working code to launch the prompt in an activity
Signature signature = createSignature();
biometricPrompt = new BiometricPrompt.Builder(context)
.setDescription("Description")
.setTitle("Title")
.setSubtitle("Subtitle")
.setNegativeButton("Cancel", context.getMainExecutor(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Log.i(TAG, "Cancel button clicked");
}
})
.build();
biometricPrompt.authenticate(new BiometricPrompt.CryptoObject(signature), cancellationSignal, context.getMainExecutor() , new BiometricPrompt.AuthenticationCallback() {...}
where context is an activity that without it it can not work
After going over the comments I have received in the question thread, I saw that the problem was in cancellationSignal, FingerprintManager
does work in Android P as well as BiometricPrompt
in views,
The actual problem was on Samsung devices (Note9 , S10) running android P,
when using FingerprintManager
a transparent screen will appear and cover the view
I had cancelationSignal.cancel
in onDetach
that would break the entire auth flow. On other devices it makes sense, since the user can close the fingerprint screen on demand