Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve method checkSelfPermission

I'm trying to make my app ready for Android 6 and now I'm stuck to the point where you need to request and check permissions.

I tried the following from the docs:

int permissionCheck = ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR);

The problem is that Android Studio says Cannot resolve method 'checkSelfPermission'.

I already included the appcompat and support lib. ContextCompat is known to AS but the method itself isn't known. I don't know what am I doing wrong - in another project I can write this method and it gets recognized.

TargetAPI is 23.

Does anyone know a solution?

like image 250
Phil Avatar asked Dec 12 '15 09:12

Phil


1 Answers

Here is how you need to call in various scenarios,

In case of activity:

 ContextCompat.checkSelfPermission(MyActivity.this,
        Manifest.permission.WRITE_CALENDAR);

In case of fragment:

 ContextCompat.checkSelfPermission(getActivity(),
        Manifest.permission.WRITE_CALENDAR);

In case of any utility class use context:

 ContextCompat.checkSelfPermission(context,
        Manifest.permission.WRITE_CALENDAR);

Comment below for further information

like image 118
Manikanta Avatar answered Sep 21 '22 22:09

Manikanta