【问题标题】:How to on/off authentication fingerprint or face recognition when used Biometric使用生物识别时如何打开/关闭身份验证指纹或面部识别
【发布时间】:2020-09-01 06:24:49
【问题描述】:

我使用生物识别来验证指纹或面部识别。它工作!但如果我的设备设置为两者,我只想使用指纹或仅使用面部识别。 我可以做还是不做?如果可以,我该怎么做? 这是我的代码

@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();
        }
    };
}

【问题讨论】:

    标签: android-biometric-prompt android-biometric


    【解决方案1】:

    如果我的设备设置为两者,我只想使用指纹或仅使用面部识别。能不能做?

    回答:根据最新的 API,你不能这样做。

    不同设备之间的生物识别功能不一致。在我的设备存储库中,我有三星 S10 设备和 MI 设备,它们都有不同的行为。 在三星 S10 设备中,我只能在设备设置中设置 FACE/FINGERPRINT。当我调用身份验证 API 时,设备设置中的设置都会生效。

    在 MI 设备中,除了 Only Face/Only Fingerprint,我可以选择同时设置两者。我认为这和你的情况一样。如果我在设备设置中设置了这两个选项,则在 authenticate() 之后,我可以使用人脸或指纹进行身份验证。

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 2010-12-26
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      • 2010-10-18
      • 2018-11-16
      • 2021-09-15
      • 2013-11-11
      相关资源
      最近更新 更多