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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With