Search code examples
androidandroid-6.0-marshmallowandroid-fingerprint-api

Allow to build Application with Android Fingerprint API in devices below Marshmallow


I have an application that uses biometrics (Fingerprint API), to let users log in. Now this application does not have reach to the users that do not have Marsh Mallow devices, but below.

When I comment a line with Cipher (API level 1), the build can run in all the devices, but with this line uncommented, I could only run it in the Marshmallow device.

I do not want this solution: https://developer.samsung.com/release-note/view.do?v=R000000009

I have used the check:

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
    // Initialize the Login Activity that has FingerPrint API
} else {
    // Initialize the second Login Activity that does not have FingerPrint API
}

This is because due to some read ahead or loading mechanisms, DVM detects that this class has Fingerprint API access in some method.

Am I correct there?, or there is some other way to allow log in to Pre Marsh Mallow Users?


Solution

  • I resolved this by putting the Fingerprint API related method, variables in a separate class called FingerPrintUtil. Now I can make the declaration of this class globally, but initialize it only if the OS version is more than Lollipop.

    private FingerPrintUtil fingerprintUtil;
    
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        if(fingerprintUtil==null){
    fingerprintUtil = new FingerPrintUtil();
    }
    fingerprintUtil.init();
    } else {
        // TODO:change the Ui of the Login Activity to login using EMail/Social login only
    }
    

    This way I can prevent Verification or Class Not found Exception. Allowing the APK to devices with lower versions of Android OS.