Search code examples
androidandroid-6.0-marshmallowfingerprintandroid-compatibilityandroid-fingerprint-api

Can I maintain a single apk to handle fingerprint scanning on Android?


While going through the Android Compatibility Definition for Android 6.0

I see the line: Device implementations with a secure lock screen SHOULD include a fingerprint sensor.

Does this mean I can't have a single version of my app which at runtime determines if the device has a finger print scanner or not? If it determines, that it has a scanner, it will launch the fingerprint scanning dialog else just ask for the PIN/Password.

Also can I use the same apk for Android versions lower than API 23?


Solution

  • You have to check

    • device SDK version
    • fingerprint hardware present
    • fingerprint authentication ready (fingerprints already enrolled)

      if (Build.VERSION.SDK_INT < 23) {
          // Handle the mechanism where the SDK is older.
      }else{
          // Handle the mechanism where the SDK is 23 or later.
          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 
          }
      }