在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();
}
});
}
});
}
});
}
在这种情况下,它将给出BIOMETRIC_ERROR_HW_NOT_PRESENT
错误。如果发生这种情况,请使用KeyguardManager。然后,他们可以使用PIN或他们设置的任何身份验证方法进行身份验证。要处理此问题,请在onAuthenticationError
中检查错误代码是否为BIOMETRIC_ERROR_HW_NOT_PRESENT
。如果是,请使用KeyguardManager
。