0

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)
Neelay Srivastava
  • 1,041
  • 3
  • 15
  • 46
champion
  • 17
  • 1
  • 10

3 Answers3

1

In my application I have a download button that requires runtime permission.

This is how I managed to do it:

public static int MY_PERMISSIONS_REQUEST_DOWNLOAD_IMAGE = 1;

btnDownLoad.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
                        urlFromDownload();
                        }
    });

public void urlFromDownload() {

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (ActivityCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.WRITE_EXTERNAL_STORAGE)
                        != PackageManager.PERMISSION_GRANTED) {

                    requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                            MY_PERMISSIONS_REQUEST_DOWNLOAD_IMAGE);
                } else {

                    DowloadFileFromUrl downloadwall = new DowloadFileFromUrl();
                    if (downloadwall.getStatus() == AsyncTask.Status.RUNNING) {
                        // My AsyncTask has not started yet
                        Toast.makeText(getActivity(), "Please wait until download is complete", Toast.LENGTH_SHORT).show();
                    } else {
                        downloadwall.execute(imageUrl);
                    }

                }
            } else {

                DowloadFileFromUrl downloadwall = new DowloadFileFromUrl();
                if (downloadwall.getStatus() == AsyncTask.Status.RUNNING) {
                    // My AsyncTask has not started yet
                    Toast.makeText(getActivity(), "Please wait until download is complete", Toast.LENGTH_SHORT).show();
                } else {
                    downloadwall.execute(imageUrl);
                }

            }

        }

I hope you understand my code. What I've done is wrote my download code twice. First for marshmallow and second for lower versions.

Marlon
  • 1,839
  • 2
  • 19
  • 42
Sagar Chavada
  • 5,169
  • 7
  • 40
  • 67
0

Put that within the below condition
if (Build.VERSION.SDK_INT >= 23) { // Your code for } else { // Code for previous versions }

raasesh
  • 161
  • 11
  • Put the code needed to be executed in Marshmallow within the if statement and the code for pre marshmallow device within else statement. – raasesh Sep 27 '16 at 07:58
  • What's the difference between your code and his? `android.os.Build.VERSION_CODES.M` references a `const int` value of 23. – jAC Sep 27 '16 at 08:01
0

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.
}
Neelay Srivastava
  • 1,041
  • 3
  • 15
  • 46
Sagar Gangawane
  • 1,985
  • 1
  • 12
  • 22