android-biometric-prompt - 使用生物识别时如何打开/关闭身份验证指纹或面部识别

标签 android-biometric-prompt android-biometric

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

@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/

相关文章:

android - 如何检查设备是否支持 BiometricPrompt 的人脸身份验证

android - 需要什么 USE_BIOMETRIC 权限?

Android BiometricPrompt : Cannot resolve symbol PromptInfo

kotlin - 使用 Jetpack Compose 的生物识别提示

java - BiometricPrompt.AuthenticationResult 中的 CryptoObject 始终为 null

android - 检测设备是用针锁或面部锁的指纹锁保护的吗?

android - 生物识别提示字幕文本在 Android 上被截断

android - 哪款 Android 设备具有 BIOMETRIC_STRONG(第 3 类)人脸身份验证?

flutter - 在 flutter 中注册用户生物识别指纹

Android - 生物识别信息是否与设备上的特定用户或一般设备相关联?