Skip to content

Instantly share code, notes, and snippets.

@Iltwats
Created May 23, 2021 17:48
Show Gist options
  • Save Iltwats/757407cb342ca22cde9f3d37bbf1597b to your computer and use it in GitHub Desktop.
Save Iltwats/757407cb342ca22cde9f3d37bbf1597b to your computer and use it in GitHub Desktop.
BiometricManager biometricManager = BiometricManager.from(this);
switch (biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK | BiometricManager.Authenticators.DEVICE_CREDENTIAL)) {
case BiometricManager.BIOMETRIC_SUCCESS:
Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
break;
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
Log.e("MY_APP_TAG", "No biometric features available on this device.");
b.biometricCardView.setVisibility(View.GONE);
break;
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
Log.e("MY_APP_TAG", "Biometric features are currently unavailable.");
b.biometricCardView.setVisibility(View.GONE);
break;
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
// Prompts the user to create credentials that your app accepts.
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, IntentIntegrator.REQUEST_CODE);
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment