无法解析方法“checkSelfPermission" [英] Cannot resolve method "checkSelfPermission"

查看:33
本文介绍了无法解析方法“checkSelfPermission"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下代码中的错误:

I am getting the error in the below code:

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

checkSelfPermission"始终为红色,表示某种错误.

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

我已经导入了import android.support.v4.content.ContextCompat;"已经.

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

以下是我的 build.gradle 内容:

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')
}

任何建议将不胜感激.

我不知道为什么这不起作用.有点菜鸟.

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

推荐答案

使用 PermissionChecker.checkSelfPermission 而不是 ContextCompat.checkSelfPermission 更正上述错误.

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

这篇关于无法解析方法“checkSelfPermission"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆