0

I'm trying to detect if the user has enrolled fingerprint or not in Android Pie using BiometricPrompt but this class will show the dialog and I want only to return true or false without any dialog.

Code

public boolean hasEnrolledFingerprints() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        //How can I return true or false without showing dialog using BiometricPrompt 
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        return fingerprintManager.hasEnrolledFingerprints();
    }
    return false;
}
Taha Sami
  • 1,565
  • 1
  • 16
  • 43

1 Answers1

1
val biometricManager =  BiometricManager.from(context)
private fun queryBiometricStatusFromDevice(): Int = biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK)

call it as below

fun hasUserConfiguredBiometric(): Boolean {
    return when (queryBiometricStatusFromDevice()) {
        BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> false
        else -> true
    }
}
DevDin
  • 46
  • 4