Reputation: 935
I used Biometric to authentication finger print or face recognition. It working! But I want only use fingerprint or only use face recognition if my device is set to both. Can I do it or not? and how I can do it if it can? Here is my code
@RequiresApi(api = Build.VERSION_CODES.P)
public void authenticateUser(@NonNull Activity activity) {
BiometricPrompt biometricPrompt = new BiometricPrompt.Builder(activity)
.setTitle("Biometric Demo")
.setSubtitle("Authentication is required to continue")
.setDescription("This app uses biometric authentication to protect your data.")
.setNegativeButton("Cancel", activity.getMainExecutor(),
(dialogInterface, i) -> {
mCallback.onCancel();
})
.build();
biometricPrompt.authenticate(mCancellationSignal, activity.getMainExecutor(),
getAuthenticationCallback());
}
@RequiresApi(api = Build.VERSION_CODES.P)
private BiometricPrompt.AuthenticationCallback getAuthenticationCallback() {
return new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode,
CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
mCallback.onError();
}
@Override
public void onAuthenticationHelp(int helpCode,
CharSequence helpString) {
super.onAuthenticationHelp(helpCode, helpString);
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
@Override
public void onAuthenticationSucceeded(
BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
mCallback.onAuthenticated();
}
};
}
Upvotes: 2
Views: 457
Reputation: 864
I want only use fingerprint or only use face recognition if my device is set to both. Can I do it or not?
Answer : As per latest APIs, You cant do it.
Biometrics feature is inconsistent among different devices. In my devices repo, I have Samsung S10 device and MI device, and both they have different behaviors. In Samsung S10 device, I can only set in device settings either FACE/FINGERPRINT. Whichever is set in device settings comes into action when I call authenticate API.
In MI device, along with Only Face/Only Fingerprint, I have option to set both. I think this is same like your case. If I set both option in device settings, after authenticate() I can authenticate either with Face or with Fingerprint.
Upvotes: 2