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:
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
For Fragment
use getActivity().checkSelfPermission
For Activity
use this..checkSelfPermission
or simply checkSelfPermission
Oh my godness - what a stupid mistake.
AS imported the supportlib as a jar and this jar was from like 2014. I just replaced the jarimport with the real dependency and know it is working.
Thanks for your help guys!
I had the same problem. In my case I added a library that was using an old appcompat version, then the compiler could not find the right appcompat.
To fix the problem I added the option {transitive = false} while importing the culprit library, and this fixed the problem.
Now I have:
api ('org.library.using.old.appcompat:1.0.1') {transitive = false}
@SuppressLint("NewApi")
I simply used this on top of my page and it works for me...
As silly as it maybe, it could be in the wrong place. I had the same problem. The bolded part is where I had originally put the code. The italic part is where it should have gone
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.i("-----------", location.toString());
}
**if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {'some code'}**
}; 'End of LocationListener method
*if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) { 'some code'}*