This might be a late but I will like to add few note:
Quick Question: Why store biometrics data when you can simply allow the device to manage the data it self ?
Also, for data authenticity, I am only guessing that if the device handles this datas by it self, then we're kind of sure that the biometric data is at lease authentic because we did not store it somewhere that we might loose it or accidentally manipulate such data and so on...
Which makes me conclude that when a user set their device biometrics, my app will simply use the data to authenticate them when necessary, so if let say the user changed their biometrics data, it will change across my app also, this is my own opinion and approach, I believe it's close to redundancy if my app has to capture the data that the device already have and if the device does not have this data, I will instruct the user via my app to set their biometrics authentications.
Note: this might not applied to everyone, it's just what I think is consistent and saver for the app users.
Below is my implementation:
STEP 1 => I add the below code to my Gradle, it's a simple library that helps consume the hardware Biometric API's and make it friendly to use, you can even clone it manually and modify to your taste.
implementation(group: 'com.an.biometric', name: 'biometric-auth', version: '0.1.0', ext: 'aar', classifier: '')
STEP 2 => I Add the permission needed to my Manifest, please don't forget that you might need to explicitly request for Biometric permission depending on the android os version.
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
Finally => Just read the comments in the code below.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){
new BiometricManager.BiometricBuilder(MainActivity.this)
.setTitle("Enter your print to access your wallet.")
.setNegativeButtonText("Try pin instead")
.build()
.authenticate(new BiometricCallback() {
@Override
public void onSdkVersionNotSupported() {
Log.e("SDK", "Not supported");
/*
* Will be called if the device sdk version does not support Biometric authentication
*/
}
@Override
public void onBiometricAuthenticationNotSupported() {
Log.e("BIOMETRIC", "Not supported");
/*
* Will be called if the device does not contain any fingerprint sensors
*/
}
@Override
public void onBiometricAuthenticationNotAvailable() {
Log.e("BIOMETRIC", "Authentication Not Available");
/*
* The device does not have any biometrics registered in the device.
*/
}
@Override
public void onBiometricAuthenticationPermissionNotGranted() {
Log.e("BIOMETRIC", "Authentication Permission Not Granted");
/*
* android.permission.USE_BIOMETRIC permission is not granted to the app
*/
}
@Override
public void onBiometricAuthenticationInternalError(String error) {
Log.e("BIOMETRIC", "Authentication Internal Error");
/*
* This method is called if one of the fields such as the title, subtitle,
* description or the negative button text is empty
*/
}
@Override
public void onAuthenticationFailed() {
Log.e("BIOMETRIC", "Authentication Failed");
/*
* When the fingerprint doesn’t match with any of the fingerprints registered on the device,
* then this callback will be triggered.
*/
}
@Override
public void onAuthenticationCancelled() {
Log.e("BIOMETRIC", "Authentication Cancelled");
pinDialog();
/*
* The authentication is cancelled by the user.
*/
}
@Override
public void onAuthenticationSuccessful() {
Log.e("BIOMETRIC", "Authentication Successful");
/*
* When the fingerprint is has been successfully matched with one of the fingerprints
* registered on the device, then this callback will be triggered.
*/
}
@Override
public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
Log.e("BIOMETRIC", "Authentication Help");
/*
* This method is called when a non-fatal error has occurred during the authentication
* process. The callback will be provided with an help code to identify the cause of the
* error, along with a help message.
*/
}
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
Log.e("BIOMETRIC", "Authentication Error");
setSelectedTab(0);
/*
* When an unrecoverable error has been encountered and the authentication process has
* completed without success, then this callback will be triggered. The callback is provided
* with an error code to identify the cause of the error, along with the error message.
*/
}
});
}
Almost forget, this implementation is for finger print only not for facial recognition, actually, located this question looking for facial recognition implementation...lol.
Happy Coding.