Evgeniy Mishustin
Evgeniy Mishustin

Reputation: 3804

Android fingerprint API - ask for a password on fingerprint failed

While using Samsung Fingerprint Spass Apis for Android I had an option(to be honest I was forced to) to ask the user for password, if fingerprint authentication was failed. Now, when Android M provide us with native FingerPrint API I can't find way to achieve the same functionality. The problem is: if user failed to provide correct fingerprint 5 times, I've got FINGERPRINT_ERROR_LOCKOUT error code from FingerprintManager, but I have no idea how to raise dialog with backup password and what Android component is in charge for that. Please' any android expert ? Thanks. Here is my callback function piece:

@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
    logger.info("Authentication error " + errorCode + " " + errString);
    super.onAuthenticationError(errorCode, errString);
    //5 failed attempts
    if (errorCode == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT) {
       //HERE SAMSUNG WAS RAISING PASSWORD DIALOG WITHOUT MY INTERVENTION 
       fingerprintCallback.onFinished(FingerprintCallback.STATUS_AUTHENTIFICATION_FAILED);
    //30 seconds no one touched the sensor
    } else if (errorCode == FingerprintManager.FINGERPRINT_ERROR_TIMEOUT) {
        fingeprintCallback.onFinished(FingerprintCallback.STATUS_TIMEOUT_FAILED);
    //cancellation signal cancel() was called
    } else if (errorCode == FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
        if (!isTimeout) {
            fingerprintCallback.onFinished(FingerprintCallback.STATUS_USER_CANCELLED);
            }
    } else {
         fingerprintCallback.onFinished(FingerprintCallback.STATUS_FAILED);
    }

    if (fingerprintDialog != null) {
        fingerprintDialog.dismiss();
    }
}

To be clear - I need the phone's PIN password, the exact password the user needs to enter when he/she enters the Fingerprint Section in security settings of the device.

Upvotes: 0

Views: 3008

Answers (1)

Herrbert74
Herrbert74

Reputation: 2715

You have to do it yourself. See the example here:

https://github.com/googlesamples/android-FingerprintDialog/blob/master/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintAuthenticationDialogFragment.java

In the onError() method it will call the goToBackup method, which will change the dialog to a password dialog.

I'm not sure how Samsung did it and what was your intention, but the current Android Fingerprint API cannot fallback to any other device authentication, so you have to use your own fall back (see the second bullet):

https://developer.android.com/training/articles/keystore.html#UserAuthentication

Upvotes: 3

Related Questions