So I have been working on implementing an authentication feature in my app so first I implemented Fingerprint authentication it works perfectly. But now am trying to add an option for pin too I have added that option with the help of documentation in the android developer
link https://developer.android.com/training/sign-in/biometric-auth
So now the problem is I have implemented but in-app when I use fingerprint it works fine but when I use pin it doesn't work as nothing happens. But the pin actually works when there is no fingerprint saved on the device
So here's the code
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser != null) {
SharedPreferences sharedPreferences = getSharedPreferences("Authentication", 0);
String bio = sharedPreferences.getString(TEXT, "");
if (bio.equals("1")) {
BiometricManager biometricManager = androidx.biometric.BiometricManager.from(this);
switch (biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK | DEVICE_CREDENTIAL)) {
// this means we can use biometric sensor
case BiometricManager.BIOMETRIC_SUCCESS:
break;
// this means that the device doesn't have fingerprint sensor
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
break;
// this means that biometric sensor is not available
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
break;
// this means that the device doesn't contain your fingerprint
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
break;
case BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED:
break;
case BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED:
break;
case BiometricManager.BIOMETRIC_STATUS_UNKNOWN:
break;
}
// creating a variable for our Executor
Executor executor = ContextCompat.getMainExecutor(this);
// this will give us result of AUTHENTICATION
final BiometricPrompt biometricPrompt = new BiometricPrompt(StartActivity.this, executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
}
// THIS METHOD IS CALLED WHEN AUTHENTICATION IS SUCCESS
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(getApplicationContext(), "Login Success", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(StartActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
});
// creating a variable for our promptInfo
// BIOMETRIC DIALOG
final BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder().setTitle("Authentication")
.setDescription("Use your fingerprint to login ")
.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_WEAK|DEVICE_CREDENTIAL).build();
biometricPrompt.authenticate(promptInfo);
}else {
Intent intent = new Intent(StartActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
I hope these are enough information for my problem