我使用生物识别来验证指纹或面部识别。它起作用了!但如果我的设备同时设置了这两种功能,我只想使用指纹或仅使用面部识别。 我可以做还是不可以做?如果可以的话我该怎么做? 这是我的代码
@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();
}
};
}
最佳答案
如果我的设备同时设置了这两种功能,我只想使用指纹或仅使用面部识别。我可以做还是不可以?
回答:根据最新的 API,你不能这样做。
不同设备之间的生物识别功能不一致。在我的设备存储库中,我有三星 S10 设备和 MI 设备,它们都有不同的行为。 在三星 S10 设备中,我只能在设备设置中设置面部/指纹。当我调用身份验证 API 时,设备设置中的任何设置都会生效。
在小米设备中,除了仅面部/仅指纹之外,我还可以选择同时设置两者。我认为这和你的情况是一样的。如果我在设备设置中设置了这两个选项,则在authenticate()之后我可以使用面部或指纹进行身份验证。
关于android-biometric-prompt - 使用生物识别时如何打开/关闭身份验证指纹或面部识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63682430/