7

I'm implementing Bio metric Prompt API for authorising user using Fingerprint. I found that Bio-metric Prompt API display different UI based on device sensor type.

enter image description here

Bio-metric API SDK call work independently to display respective UI based on sensor type.

enter image description here

Now the concern is:

  1. In case of rear(at side of device in some devices) sensored device, it display dialog which also use to display error if any.
  2. But in case of in/under display sensored device, it simply display a fingerprint impression and that does not display any error in case.

Now the question is:

  1. Is there any API feature using that in-display prompt can display error.
  2. In case not, how we can differentiate between both type of sensor device so can handle error explicitly.
Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18
CoDe
  • 11,056
  • 14
  • 90
  • 197

3 Answers3

2

In case you are still experiencing this problem, There is a recently published blog post that sheds some light on why the API behaves the way it does. The post also shows you how to use the API correctly.

You should only need to use the biometrics library in AndroidX.

Essentially you get three callbacks:

  1. onAuthenticationSucceeded() is called when the user has been authenticated using a credential that the device recognizes.

  2. onAuthenticationError() is called when an unrecoverable error occurs.

  3. onAuthenticationFailed() is called when the user is rejected, for example when a non-enrolled fingerprint is placed on the sensor, but unlike with onAuthenticationError(), the user can continue trying to authenticate.

You can use any of these callbacks to post messages to your user through a Toast or such.

Isai Damier
  • 976
  • 6
  • 8
1

There is indeed an API and callback for you to utilize in this situation. The package you are looking for is either the Biometrics Package for API levels 28+ or the Fingerprint package for API levels 23-27.

The callback to which I am referring can be found here for API 28+ and here for API 23-27.

Here is some sample code with how the callback is initialized:

/**
 * Helper class for authentication callback
 */
@RequiresApi(api = Build.VERSION_CODES.M)
private class FingerprintHandler extends FingerprintManager.AuthenticationCallback {
    private FingerprintHandler(){}

    /**
     * Called when an unrecoverable error has been encountered and the operation is complete.
     * No further callbacks will be made on this object.
     * @param errMsgId An integer identifying the error message
     * @param errString A human-readable error string that can be shown in UI
     */
    @Override
    public void onAuthenticationError(int errMsgId, CharSequence errString) {
        //Authentication error. The 'errString' is meant to be displayed to the user
        //Handle logic here
    }

    /**
     * Called when a fingerprint is valid but not recognized.
     */
    @Override
    public void onAuthenticationFailed() {
        //Authentication failed (Fingerprints don't match ones on device)
        //Handle logic here
    }

    /**
     * Called when a recoverable error has been encountered during authentication. The help
     * string is provided to give the user guidance for what went wrong, such as
     * "Sensor dirty, please clean it."
     * @param helpMsgId An integer identifying the error message
     * @param helpString A human-readable string that can be shown in UI
     */
    @Override
    public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
        //Non-Fatal error (IE moved finger too quickly). The helpString can be displayed to the user to help them retry.
        //Handle logic here
    }

    /**
     * Called when a fingerprint is recognized.
     * @param result An object containing authentication-related data
     */
    @Override
    public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
        //Authentication Succeeded. They are good to go and it matches the stored one
        //Handle logic here
    }
}

And here is some sample usage in a class of mine if the above code is not enough to get you moving.

With regards to utilizing an alert or display, I just use the callback info in conjunction with a Dialog or an on-screen textview if I don't want to block the screen.

PGMacDesign
  • 6,092
  • 8
  • 41
  • 78
  • Hi, Thanks for your reply. I'm using `androidx.biometric.BiometricPrompt` component to receive callback. First, this does not provide anything related with `onAuthenticationHelp` but it's ok as don't see much use of this. Because Biometric SDK API display dialog itself handle this. But for me problem still remained same, how to handle `onAuthenticationError` and `onAuthenticationFailed` for on-screen fingerprint sensor. I can take some custom textView it's ok, but then how to recognise use of it, because for rear-sensor SDK uses own dialog to show any error/hint. Any finding around this !! – CoDe Sep 28 '19 at 00:10
  • This may be one of those situations that is better served *not* using the built-in `BiometricPrompt` and instead building your own logic like what I posted above. If the conflict is arising within the `prompt` class you cannot alter at all, you may want to abstract back a level where you will be able to handle the `onAuthenticationError` and `onAuthenticationFailed` for all situations. – PGMacDesign Sep 30 '19 at 14:41
  • even checked with both API version `hardware` and `androidx` but it's not making any difference. It simply not able to display error message if it's in-display biometric sensor. Any other finding around ! – CoDe Oct 16 '19 at 09:56
0

I don't think your problem is something to do with In-display/Rear sensor. In my testing analyses with Biometricx APIs, I found both In-display/Rear sensor types showed error in the system UI when biometrics auth failed. It also depends on the device you are testing, device manufacturer may have decided not to support the Biometrics APIs. In my case, when I tested on Samsung S5 device, even though device had in-display sensor, canAuthenticate() returned false.

Shanker
  • 864
  • 6
  • 24
  • Do you have any working example !! I checked this behaviour for launcher-lock screen and that show message in screen as you mentioned, but that must be some custom UI component from app side, as I didn't find any system control when it comes to in-display sensor. – CoDe Sep 30 '19 at 02:11