I\'m asked to show certain UI elements depending on the presence of biometric hardware. For Android 23-27 I use FingerprintManager#isHardwareDetected() and
In my biometrics, I used these and a few more checks to make sure that the device was capable and the fingerprint was enabled. In Kotlin I created an Object class and called it utilities.
object BiometricUtilities {
fun isBiometricPromptEnabled(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
}
fun isSdkVersionSupported(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
}
fun isHardwareSupported(context: Context): Boolean {
val fingerprintManager = FingerprintManagerCompat.from(context)
return fingerprintManager.isHardwareDetected
}
fun isFingerprintAvailable(context: Context): Boolean {
val fingerprintManager = FingerprintManagerCompat.from(context)
return fingerprintManager.hasEnrolledFingerprints()
}
}
Then in my bioManager class, I placed the conditional statements under a function called authenticate that implements BiometricCallback
fun authenticate(biometricCallback: BiometricCallback) {
if (!BiometricUtilities.isHardwareSupported(context)) {
biometricCallback.onBiometricAuthenticationNotSupported()
return
}
if (!BiometricUtilities.isFingerprintAvailable(context)) {
val intent = Intent(Settings.ACTION_SECURITY_SETTINGS)
biometricCallback.onBiometricAuthenticationNotAvailable()
return
}
displayBiometricDialog(biometricCallback)
}
This way you can check for availability of hardware and presence of fingerprint on the device and let the OS help you to display a prompt or not