0

I want to integrate Biometric detection in my app. I want to check 2 condition before show the BiometricPromt authentication to the user:

  1. Detect the Biometric sensor/hardware available or not in the device.
  2. Detect any Biometric is enrolled or not in the device.

Have tried lots of SO answers like this but didn't solve my requirement. Whenever am trying to check for hardware using below method every time used to get BIOMETRIC_ERROR_NONE_ENROLLED status and even for checking the fingerprint enrolled or not getting the same status BIOMETRIC_ERROR_NONE_ENROLLED.

Is there any way to detect biometric hardware presence and user enrolment in the device there will get the respective status based on condition like BIOMETRIC_ERROR_NONE_ENROLLED and BIOMETRIC_ERROR_NO_HARDWARE? And will get the accurate status?

Menu
  • 677
  • 1
  • 12
  • 30

1 Answers1

0

I think this will help you and is what you are looking for.

val biometricManager = BiometricManager.from(this)
when (biometricManager.canAuthenticate(BIOMETRIC_STRONG or DEVICE_CREDENTIAL)) {
BiometricManager.BIOMETRIC_SUCCESS ->
    Log.d("MY_APP_TAG", "App can authenticate using biometrics.")
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE ->
    Log.e("MY_APP_TAG", "No biometric features available on this device.")
BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE ->
    Log.e("MY_APP_TAG", "Biometric features are currently unavailable.")
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> {
    // Prompts the user to create credentials that your app accepts.
    val enrollIntent = Intent(Settings.ACTION_BIOMETRIC_ENROLL).apply {
        putExtra(Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED,
            BIOMETRIC_STRONG or DEVICE_CREDENTIAL)
    }
    startActivityForResult(enrollIntent, REQUEST_CODE)
    }
}

In the when condition you get the biometric success, error with the hardware, any enrolled or biometric allowed or not in the device.

For more clearance please refer here

Khush Parmar
  • 316
  • 2
  • 9
  • Yeah even have tried above solution also but if hardware is not present then getting below condition as True: BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED not this one BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE – Menu Jun 26 '23 at 10:08
  • Strange, this must be the device specific behaviour else this will not happening on all the devices. Although i found something which may helpful to you please refer this question :- https://stackoverflow.com/questions/50968732/determine-if-biometric-hardware-is-present-and-the-user-has-enrolled-biometrics – Khush Parmar Jun 26 '23 at 10:17
  • Yes even am also surprised why am getting same status for different condition. have checked in emulators as don't have mobile in which fingerprint sensor is disabled. – Menu Jun 26 '23 at 10:50
  • Okay strange, but for surety must check with device as well which don't have the Biometric.. – Khush Parmar Jun 26 '23 at 11:49