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

How to secure pre marshmallow application crashings


I am making an application that contains a part of activities that can be executed on pre marshmallow devices and some part of activities on marshmallow and above. So what I want to do is don't let the application crash on pre marshmallow device that runs the activity that is supported on marshmallow device and just show a toast that your device does not support this module to access.

Here I am stuck on finger print module that crashes the applications on pre marshmallow device.

 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {

//do something
}
else
showToastMessage();

Error

FATAL EXCEPTION: main
                java.lang.VerifyError: com/example/android/fingerprintdialog/MainActivity
                at java.lang.Class.newInstanceImpl(Native Method)
                at java.lang.Class.newInstance(Class.java:1130)
                at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
                at android.app.ActivityThread.access$700(ActivityThread.java:159)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:176)
                at android.app.ActivityThread.main(ActivityThread.java:5419)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
                at dalvik.system.NativeStart.main(Native Method)

Solution

  • Just check whether installed app is using marshmallow or above Android OS.

    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M)
    {
     // FingerPrint is supported by Android
      // Show the FingerPrint touch screen.
    }
    else
    {
    //FingerPrint is not supported by Android
    //Don't show the FingerPrint touch screen.
    }