3

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

BennyP
  • 1,737
  • 1
  • 18
  • 24
  • _"Now in Android P, I have to use BiometricPrompt"_ Depends on what you mean by _"have to"_; `FingerprintManager` is deprecated, but it's still available, _"where context is an activity"_ I don't see anything in the documentation about it having to be an `Activity` specifically. Looking at the source code for `BiometricPrompt`, all it uses the context for is to call `getSystemService` and `getPackageManager`. Since you already need a `Context` to get a `FingerprintManager`, have you tried just using that same context to create a `BiometricPrompt`? – Michael Mar 18 '19 at 10:10
  • Yes, and I have received `onAuthenticationError` automatically. also, when using FingerprintManager in android P, also `onAuthenticationError` is called automatically the working code of FingerprintManager deployed in production, doesn't work for my users in android P, therefor this question was raised p.s. I also looked in BiometricPrompt source code and saw plain Context, and not activity. so this is weid for me as well – BennyP Mar 18 '19 at 10:33
  • _"when using FingerprintManager in android P, also onAuthenticationError is called automatically"_ I've used `FingerprintManager` successfully on both Android P (Galaxy S10) and Android Q Beta (Pixel 3). – Michael Mar 18 '19 at 10:37
  • interesting, I'll take a look. can you paste a sample code so I can maybe see the differences? – BennyP Mar 18 '19 at 11:03

1 Answers1

0

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

BennyP
  • 1,737
  • 1
  • 18
  • 24
  • Hi, @BennyP. Do you have any ideas about how to disable the "transparent screen" popped up by the Samsung devices (S10). My app has its own fingerprint prompt dialog and I don't want the users to see 2 overlapped prompt screens. Thanks! – Yanni Chang Mar 01 '20 at 16:45
  • there is no way afaik, you can use BiometricPrompt to customize your message to the user – BennyP Mar 02 '20 at 06:00