0

在 Android 开发者参考中,我找到了这句话:

此调用预热生物特征硬件,显示系统提供的对话框,并开始扫描生物特征。

这个调用验证用户是否有智能手机上的指纹?如果不是,我如何验证?

 private void setLoginFingerprint() {
        final Executor executor = Executors.newSingleThreadExecutor();
        final BiometricPrompt biometricPrompt = new BiometricPrompt.Builder(this)
                .setTitle("")
                .setSubtitle("")
                .setDescription("")
                .setNegativeButton("Cancel", executor, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).build();


        loginFingerprint = findViewById(R.id.ll_leitor_digital);
        loginFingerprint.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                biometricPrompt.authenticate(new CancellationSignal(), executor, new BiometricPrompt.AuthenticationCallback() {
                    @Override
                    public void onAuthenticationError(int errorCode, CharSequence errString) {
                        super.onAuthenticationError(errorCode, errString);
                        LoginActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(LoginActivity.this, "Error!", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }

                    @Override
                    public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
                        super.onAuthenticationSucceeded(result);
                        LoginActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(LoginActivity.this, "Auth!", Toast.LENGTH_SHORT).show();

                            }
                        });
                    }

                    @Override
                    public void onAuthenticationFailed() {
                        super.onAuthenticationFailed();
                        LoginActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(LoginActivity.this, "Error", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                });
            }
        });
    }
4

1 回答 1

1

在这种情况下,它会给出一个BIOMETRIC_ERROR_HW_NOT_PRESENT错误。如果发生这种情况,请使用 KeyguardManager。然后他们可以使用 PIN 或他们设置的任何身份验证方法进行身份验证。要处理此问题,请在您的onAuthenticationError中检查错误代码是否为BIOMETRIC_ERROR_HW_NOT_PRESENT. 如果是,请使用KeyguardManager.

于 2020-04-20T18:57:15.893 回答