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.