I am trying to implement Biometric prompt API to authenticate user using fingerprint verification. I am successfully able to integrate Biometric prompt and it is working on andorid 9.0. But as the documentation suggests Biometric api is also backwards compatible, but when I build dialog using below code it shows API support warning.
Call requires API level 28 (current min is 15): new android.hardware.biometrics.BiometricPrompt.Builder less... (Ctrl+F1) This check scans through all the Android API calls in the application and warns about any calls that are not available on all versions targeted by this application (according to its minimum SDK attribute in the manifest)
mBiometricPrompt = new BiometricPrompt.Builder(this)
.setDescription("Description")
.setTitle("Title")
.setSubtitle("Subtitle")
.setNegativeButton("Cancel", getMainExecutor(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Log.i(TAG, "Cancel button clicked");
}
})
.build();
What can I do to make this work on lower apis? Here is Screenshot.
Looks like Biometric Prompt API for older version is still in alpha. If you are ok with an alpha version you can use this in build.gradle
compile group: 'androidx.biometric', name: 'biometric', version: '1.0.0-alpha02'
Source: https://mvnrepository.com/artifact/androidx.biometric/biometric/1.0.0-alpha02
There are only two versions listed here
Source: https://mvnrepository.com/artifact/androidx.biometric/biometric
As per the library description, it says
The Biometric library is a static library that you can add to your Android application. It invokes BiometricPrompt on devices running P and greater, and on older devices will show a compat dialog. Compatible on devices running API 14 or later.
Which would mean that all you need is this compat library and it would work on all version of Android. No need to keep two different version for above Android 9 and below Android 9.