0

I am trying to add a small section on my app that detects if an android device has a built in Fingerprint Hardware. There are two certain pages where this topic was discussed, respectively:

Marshmallow Fingerprint Scanner Hardware Presence

and

Android check for fingerprint scanner is available

but none of them gave me a working solution and I am looking for something that should work on an API as old as 14.

Any help would be appreciated!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
M'aiq the Coder
  • 762
  • 6
  • 18

3 Answers3

2

You have to use method isHardwareDetected on FingerprintManager class.

Determine if fingerprint hardware is present and functional. Returns true if hardware is present and functional, false otherwise.

  // Check if we're running on Android 6.0 (M) or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    //Fingerprint API only available on from Android 6.0 (M)
    FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
    if (!fingerprintManager.isHardwareDetected()) { 
        // Device doesn't support fingerprint authentication     
    } else if (!fingerprintManager.hasEnrolledFingerprints()) { 
        // User hasn't enrolled any fingerprints to authenticate with 
    } else { 
        // Everything is ready for fingerprint authentication 
    }
}

Don't forget to add permission to access fingerprint functions in AndroidManifest:

<uses-permission android:name="android.permission.USE_FINGERPRINT" />

With Support Library

If you don't want to check Build.VERSION, it's also possible to check on device lower than Android 6.0 with Support Library

Add dependency:

compile "com.android.support:support-v4:23.0.0"

And use FingerprintManagerCompat class as this:

FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(context);

if (!fingerprintManagerCompat.isHardwareDetected()) { 
    // Device doesn't support fingerprint authentication     
} else if (!fingerprintManagerCompat.hasEnrolledFingerprints()) { 
    // User hasn't enrolled any fingerprints to authenticate with 
} else { 
    // Everything is ready for fingerprint authentication 
}
Muhammad Hassaan
  • 874
  • 6
  • 18
1

add fingerprint permission in manifest file and add this code to detect fingerprint hardware , remember this will detect only when the finger print is enable from phone settings .

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    {
        //Get an instance of KeyguardManager and Fingerpr`enter code here`intManager//
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);}
        //Check whether the device has a fingerprint sensor//
        if (!fingerprintManager.isHardwareDetected())
      { //any thing}
Ahsan Malik
  • 399
  • 2
  • 3
  • 13
0

I believe there's no official fingerprint API in old versions of Android that apps can use. You can check if the API version is newer than 23, and if not, the device hasn't a fingerprint sensor you can use.

Jarne
  • 39
  • 2