0

I am using Fingerprint authentication in my app. To decide whether a device has a fingerprint hardware or not I am using this

getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT);

in the official document it is mentioned that it was added in API 23.

What is working

This API is working fine for all the API 24 and above. (I have tested on 24, 26 and 30)

What is not working

It returns false always even the device has fingerprint hardware available.

My questions are

  • It it a bug?
  • Am I missing something? Does my understanding of hasSystemFeature() is incorrect ?
  • What is a more reliable way to check ?

I found a very interesting answer here which says that it can return false even if device has fingerprint hardware because the feature may not be specified in config file. I don't know how credible that it.

Rohit Singh
  • 16,950
  • 7
  • 90
  • 88

1 Answers1

0

Use Android Biometric Library, for java is androidx.biometric:biometric:1.2.0-alpha04 and for kotlin is androidx.biometric:biometric-ktx:1.2.0-alpha04

in java

int canAuthenticate = BiometricManager.from(context).canAuthenticate(BIOMETRIC_STRONG);
if(canAuthenticate == BIOMETRIC_ERROR_NO_HARDWARE) {
   //The device has no fingerprint sensot
} else {
   //do some stuff work here
}

in kotlin

val canAuthenticate = BiometricManager.from(context).canAuthenticate(BIOMETRIC_STRONG)
if(canAuthenticate == BIOMETRIC_ERROR_NO_HARDWARE) {
   //The device has no fingerprint sensot
} else {
   //do some stuff work here
}
OneDev
  • 557
  • 3
  • 14
  • 2 reasons I would not use that. 1) FingerprintManager is deprecated. 2) FingerprintManager is returning null if the device only has FaceID authentication (In Pixel 4) – Rohit Singh Jan 29 '22 at 16:34
  • I Update my answer, please check it, I hope it can help you – OneDev Jan 29 '22 at 17:41