Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display authentication error for in-display Bio-metric Prompt fingerprint. #Android

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.
like image 700
CoDe Avatar asked Sep 17 '19 12:09

CoDe


2 Answers

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.

like image 143
Isai Damier Avatar answered Sep 29 '22 02:09

Isai Damier


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.

like image 29
PGMacDesign Avatar answered Sep 29 '22 01:09

PGMacDesign