Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve method "checkSelfPermission"

I am getting the error in the below code:

 if (ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
}

The "checkSelfPermission" is always red indicating some kind of error.

I have imported "import android.support.v4.content.ContextCompat;" already.

The below is my build.gradle content:

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
    applicationId "com.xyz.user.abc"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//    testCompile 'junit:junit:4.12'
compile files('libs/volley.jar')
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.google.android.gms:play-services:10.2.1'
compile 'com.android.support:design:25.3.0'
compile 'junit:junit:4.12'
//    compile 'com.google.android.gms:play-services-appindexing:10.2.1'
//    compile 'com.google.android.gms:play-services:9.8.0'
//    compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.android.support:support-v4:25.3.0'
compile files('libs/android-support-v4.jar')
}

Any advice will be really appreciated.

I got no idea why this is not working. Kind of a noob at this.

like image 335
remedcu Avatar asked Apr 02 '17 19:04

remedcu


1 Answers

Using PermissionChecker.checkSelfPermission instead of ContextCompat.checkSelfPermission corrects the above error.

like image 60
remedcu Avatar answered Nov 04 '22 13:11

remedcu