我使用生物识别来验证指纹或面部识别。它工作!但如果我的设备设置为两者,我只想使用指纹或仅使用面部识别。我可以做还是不做?如果可以,我该怎么做?这是我的代码
@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();
}
};
}