Reputation: 21
I am implementing biometric auntentication in my application. Before showing up the prompt I want to check whether it is enable or disabled usecase. For the first case, biometric success callback is fetched. I disabled the fingerprint in my mobile settings and tried to fecth value,it is returning true(0)-> BIOMETRIC_SUCCESS.
Here is my code snippet
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button authenticateButton = findViewById(R.id.button_biometric);
authenticateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean result = hasBiometricCapability();
Log.d("Mainactivity", String.valueOf(result));
Toast.makeText(MainActivity.this, String.valueOf(result), Toast.LENGTH_SHORT).show();
//showBiometricPrompt();
}
});
}
private boolean hasBiometricCapability() {
BiometricManager biometricManager = BiometricManager.from(this);
Log.d("Mainactivity", String.valueOf(biometricManager.canAuthenticate()));
return biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS;
}
private void showBiometricPrompt() {
BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric Authentication")
.setDescription("Please authenticate with your biometrics to continue")
.setDeviceCredentialAllowed(false)
.setNegativeButtonText("cancel")
.build();
BiometricPrompt biometricPrompt = new BiometricPrompt(this,
ContextCompat.getMainExecutor(this),
new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(getApplicationContext(), "Authentication successful", Toast.LENGTH_SHORT).show();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
Toast.makeText(getApplicationContext(), "Authentication failed", Toast.LENGTH_SHORT).show();
}
});
biometricPrompt.authenticate(promptInfo);
}
In the above code snippet am getting true even i disable the fingerprint option in the device settings manually. I should get error/ false response if it is disabled. If it is deleted, I am getting as false but I have no idea how to check for disabled condition.
Upvotes: 2
Views: 156