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


  该调用可预热生物识别硬件,显示系统提供的信息。
  对话框,然后开始扫描生物特征。


此呼叫验证用户是否在smarthphone上具有指纹?如果没有,我该如何验证?

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

最佳答案

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

09-08 06:14