This is my code to show the prompt for fingerprint authentication in Android P:
private void displayBiometricPrompt() {
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Fingerprint Authentication cancelled", Toast.LENGTH_LONG);
}
};
BiometricPrompt bm = new BiometricPrompt.Builder(getApplicationContext())
.setTitle("Add a title")
.setSubtitle("Add a subtitle")
.setDescription("Add a description")
.setNegativeButton("CANCEL", getMainExecutor(), onClickListener)
.build();
bm.authenticate(getCancellationSignal(), getMainExecutor(), getAuthenticationCallback());
}
Unfortunately it is not working, since it's not displaying any dialog or prompt for fingerprint authorization.
There is also no error in my code, I do not get any exceptions.
I checked the permissions and everything seems to be as required for the biometric prompt.
There is just nothing happening.
Can anyone help me in finding out how?
Appreciate any Help
you need to check a few things in order to work with Biometric Prompt :
1- the running android version should be Pie or above
public static boolean isBiometricPromptEnabled() {
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P);
}
2- the hardware should be available
public static boolean isHardwareSupported(Context context) {
FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(context);
return fingerprintManager.isHardwareDetected();
}
3- the use must have enrolled at least 1 finger print in the settings
private static boolean isFingerprintAvailable(Context context) {
FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(context);
return fingerprintManager.hasEnrolledFingerprints();
}