android ContextCompat.checkSelfPermission() not found
Asked Answered
S

3

26

I am trying to make runtime permissions backward compatible with older devices but using the support library i cant find checkSelfPermission() static call in ContextCompat class, but its documented here

Here is my project gradle settings:

defaultConfig {
    applicationId "org.myprogram.cool"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 39
    versionName "3.0"
}

and here is the dependencies:

compile 'com.google.android.gms:play-services:+'
compile 'com.squareup:otto:1.3.5'
compile 'com.android.support:appcompat-v7:22.1.1'

any idea what i am missing ?

Sanatory answered 7/10, 2015 at 3:30 Comment(0)
A
7

If you have migrated from eclipse adding the below line wont work

compile 'com.android.support:appcompat-v7:23.0.1'

While migrating, it adds appcompatv4 as an external dependent library. Make sure you have deleted the appcompatv4 library from the libs folder and then it should start working

Acid answered 12/5, 2016 at 18:24 Comment(0)
U
40

checkSelfPermission() didn't get introduced into the native Context until API 23. So you will need to use at least version 23.0.0 of the support library.

You should change this

compile 'com.android.support:appcompat-v7:22.1.1'

to this

compile 'com.android.support:appcompat-v7:23.0.1'

Uphroe answered 7/10, 2015 at 4:27 Comment(2)
I tried this thing but compilation error as minSdkVersion 16 ! how to solve this ?Guienne
please beware of this behavior when your minSdkVersion < 23 #33407750Forgiven
A
7

If you have migrated from eclipse adding the below line wont work

compile 'com.android.support:appcompat-v7:23.0.1'

While migrating, it adds appcompatv4 as an external dependent library. Make sure you have deleted the appcompatv4 library from the libs folder and then it should start working

Acid answered 12/5, 2016 at 18:24 Comment(0)
C
0
  1. Make sure class exampleActivity class is extending from AppCompatActivity.

  2. Make sure that your minSdkVersion is 23 in the build.gradle file.

  3. Sync your gradle after making this change.

That should work.

Cheriecherilyn answered 23/5, 2020 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.