Android fingerprint API - ask for a password on fingerprint failed

放肆的年华 提交于 2020-02-03 01:54:25

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/37859211/android-fingerprint-api-ask-for-a-password-on-fingerprint-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!