关于 BiometricPrompt.authenticate()

About the BiometricPrompt.authenticate()

在 Android 开发者参考中我发现了这句话:

This call warms up the biometric hardware, displays a system-provided dialog, and starts scanning for a biometric.

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

 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.