Face Biometric is not working on All phones except Samsung mobile, the issue is when I try to authenticate in my Vivo, Motorola, Oneplus, Oppo, and Mi phone face authentication works okay… but I didn’t get a callback so, and dialog is not dismiss
public class MainActivity extends AppCompatActivity {
private Executor executor;
private BiometricPrompt biometricPrompt;
private BiometricPrompt.PromptInfo promptInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
executor = ContextCompat.getMainExecutor(this);
biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback(){
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString){
super.onAuthenticationError(errorCode, errString);
tvAuthStatus.setText("Error :" +errString);
}
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result){
super.onAuthenticationSucceeded(result);
tvAuthStatus.setText("Successful Auth"); biometricPrompt.cancelAuthentication();
}
@Override
public void onAuthenticationFailed(){
super.onAuthenticationFailed();
tvAuthStatus.setText("Authentication Failed");
}
});
btnAuth.setOnClickListener(view -> startBiometricAuthentication());
promptInfo= new BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric Authentication")
.setSubtitle("Login Using fingerprint or face")
.setNegativeButtonText("Cancel")
.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_WEAK)
.setConfirmationRequired(false)
.build();
}
private void startBiometricAuthentication() {
BiometricManager biometricManager = BiometricManager.from(this);
switch (biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK | BiometricManager.Authenticators.DEVICE_CREDENTIAL)) {
case BiometricManager.BIOMETRIC_SUCCESS:
biometricPrompt.authenticate(promptInfo);
Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
break;
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
showToast("Biometric authentication is not available on this device");
Log.e("MY_APP_TAG", "No biometric features available on this device.");
break;
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
Log.e("MY_APP_TAG", "Biometric features are currently unavailable.");
break;
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
final Intent enrollIntent = new Intent(Settings.ACTION_BIOMETRIC_ENROLL);
enrollIntent.putExtra(Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED,BiometricManager.Authenticators.BIOMETRIC_WEAK | BiometricManager.Authenticators.DEVICE_CREDENTIAL);
startActivityForResult(enrollIntent, 1001);
break;
}
}
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
@Override
protected void onStop() {
super.onStop();
if (biometricPrompt != null) {
biometricPrompt.cancelAuthentication();
}
}
}
Face Biometric is not working on All phones except Samsung mobile, the issue is when I try to authenticate in my Vivo, Motorola, Oneplus, Oppo, and Mi phone face authentication works okay… but I didn’t get a callback so, and dialog is not dismiss