1

Following exception was fired when using the method checkSelfPermission. The targetSDKVersion is 21 for the application.

FATAL EXCEPTION: main Process: app.Rvamd.RecoverAllMyDeletedFile, PID: 3700 java.lang.NoSuchMethodError: No static method checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/app.Rvamd.RecoverAllMyDeletedFile-1/base.apk)

Does anybody have idea on this? The method was invoked properly for another application in same emulator device. Apart from this, can I know how support library methods are selected by phone/emulator (method is invoked properly for some application while others aren't) ?

The code is as below

     if (ContextCompat.checkSelfPermission(this,
                        Manifest.permission.READ_CONTACTS)
                != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.READ_CONTACTS},
                        MY_PERMISSIONS_REQUEST_READ_CONTACTS);
                return;


        }
ShaAk
  • 190
  • 1
  • 12

1 Answers1

1

You might need to upgrade compileSdkVersion to 23. This is because runtime permission feature is added since API 23.

Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
  • To be clear, Does the phone select support library version by looking at the `compileSdkVersion` ? I noticed `compileSdkVersion` is not considered after the compilation. – ShaAk Dec 04 '17 at 05:05
  • I'm not exactly sure on that. There are various options on the differences among `compileSdkVersion` and `targetSdkVersion` - https://stackoverflow.com/questions/26694108/what-is-the-difference-between-compilesdkversion-and-targetsdkversion It still sound very confusing to me. My rule of thumb is that, I always set `compileSdkVersion` equals to `targetSdkVersion`, although they are allowed to be different. – Cheok Yan Cheng Dec 04 '17 at 05:24