我在我的项目中实施了指纹生物识别身份验证。如果用户想通过单击“使用密码”按钮来使用模式/密码/密码,我已经设置了一个后备身份验证。我已经通过使用第一次工作的 setDeviceCredentialAllowed(true) 来做到这一点。但是每当我再次这样做时,图案/pin/密码屏幕就再也不会出现了。我在 logcat 控制台中得到以下日志:
BiometricPromptCompat:无法检查设备凭据。未找到父处理程序
这是我的代码供参考。提前致谢。
executor = ContextCompat.getMainExecutor(this);
biometricPrompt = new BiometricPrompt(MainActivity.this,
executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode,
@NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
Toast.makeText(getApplicationContext(),
"Authentication error: " + errString, Toast.LENGTH_SHORT)
.show();
}
@Override
public void onAuthenticationSucceeded(
@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(getApplicationContext(),
"Authentication succeeded!", Toast.LENGTH_SHORT).show();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
Toast.makeText(getApplicationContext(), "Authentication failed",
Toast.LENGTH_SHORT)
.show();
}
});
promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
.setDeviceCredentialAllowed(true)
.setConfirmationRequired(true)
.build();
biometricPrompt.authenticate(promptInfo);