'PackageManager.FEATURE_FINGERPRINT always returns false on API 23
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.
Solution 1:[1]
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
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
