1

I'm trying to learn how to implement a fingerprint API.

In one of fingerprint guides, it gave me a code

@RequiresApi(api = Build.VERSION_CODES.P)
public class BiometricCallbackV28 extends BiometricPrompt.AuthenticationCallback {

    private BiometricCallback biometricCallback;
    public BiometricCallbackV28(BiometricCallback biometricCallback) {
        this.biometricCallback = biometricCallback;
    }


    @Override
    public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
        super.onAuthenticationSucceeded(result);
        biometricCallback.onAuthenticationSuccessful();
    }


    @Override
    public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
        super.onAuthenticationHelp(helpCode, helpString);
        biometricCallback.onAuthenticationHelp(helpCode, helpString);
    }


    @Override
    public void onAuthenticationError(int errorCode, CharSequence errString) {
        super.onAuthenticationError(errorCode, errString);
        biometricCallback.onAuthenticationError(errorCode, errString);
    }


    @Override
    public void onAuthenticationFailed() {
        super.onAuthenticationFailed();
        biometricCallback.onAuthenticationFailed();
    }
}

But shouldn't there be a test whether the authentication passed THEN call onAuthenticationSucceeded? I don't see anywhere that calls public void onAuthenticationSucceeded. How does it know that the fingerprint matches? Who calls the method?

Carol Ward
  • 699
  • 4
  • 17

1 Answers1

2

But shouldn't there be a test whether the authentication passed

The system knows whether the authentication passed, by comparing the scanned fingerprint against fingerprints registered by the user

I don't see anywhere that calls public void onAuthenticationSucceeded

The framework calls all of those callback methods, based on the results from the biometric hardware.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So an entity outside of an app calls public void onAuthenticationSucceeded? – Carol Ward Jul 02 '19 at 18:07
  • 1
    @CarolWard: Yes, to the same extent that an entity outside of an app calls `onCreate()` of your `Activity`, `onStartCommand()` of your `Service`, etc. – CommonsWare Jul 02 '19 at 18:19