The method checkSelfPermission(Context, String) is undefined for the type ContextCompat

前端 未结 3 1435
余生分开走
余生分开走 2020-12-19 11:18
Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
         


        
相关标签:
3条回答
  • 2020-12-19 11:26

    You can set target android of your project to android 6.0 or higher. Then add android-support-v4.jar

    0 讨论(0)
  • 2020-12-19 11:38

    This issue occurs because the support library is out of date.

    If you're using Eclipse, I've found the most simple solution is to right-click the project and go to:

    Android Tools > Add support library...

    If this doesn't resolve the issue, you probably need to update the SDK first:

    Window > Android SDK Manager > Install Updates

    The support library will be added/updated and will no longer show this error.

    0 讨论(0)
  • 2020-12-19 11:50

    ContextCompat.checkSelfPermission() requires support library in version 23 or higher.

    Add in dependencies block in lower-level build.gradle:

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

    If you have previous version here (which you probably have), you should replace lane with provided by me.

    0 讨论(0)
提交回复
热议问题