Reputation: 55
In the Android Developer reference I found this quote:
This call warms up the biometric hardware, displays a system-provided dialog, and starts scanning for a biometric.
This calls verify if the user have or not the fingerprint on smarthphone? If not, how I verify?
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();
}
});
}
});
}
});
}
Upvotes: 0
Views: 1039
Reputation: 818
In this case, it would give an BIOMETRIC_ERROR_HW_NOT_PRESENT
error. If that happens, use a KeyguardManager. Then they can authenticate with a PIN or whatever authentication method they set up. To handle this, in your onAuthenticationError
, check if the error code is BIOMETRIC_ERROR_HW_NOT_PRESENT
. If it is, use the KeyguardManager
.
Upvotes: 1