Reputation: 1697
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;
}
Upvotes: 0
Views: 558
Reputation: 46
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
}
}
Upvotes: 1