2

我在我的项目中实施了指纹生物识别身份验证。如果用户想通过单击“使用密码”按钮来使用模式/密码/密码,我已经设置了一个后备身份验证。我已经通过使用第一次工作的 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);
4

1 回答 1

2

我只在小米设备中遇到过这个问题,如果我不得不再次调用生物特征验证来修复这个错误,我每次都必须创建一个新的 PromptInfo 而不是重复使用第一个。

val promptInfo = BiometricPrompt.PromptInfo.Builder()
                .setTitle(getString(R.string.authenticate_card_creation))
                .setSubtitle(getString(R.string.authenticate_creation_description_virtual))
                .setDeviceCredentialAllowed(true)
                .setConfirmationRequired(false)
                .build()
于 2020-07-31T10:21:43.653 回答