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