Cannot resolve method “checkSelfPermission”

房东的猫 提交于 2020-01-01 05:50:14

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/43172519/cannot-resolve-method-checkselfpermission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!