I'm trying to check a permission in API 23 and above like this:
int result = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
But it can't find Manifest.permission.READ_EXTERNAL_STORAGE
.
This is because in my manifest the permission is set up like this:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
So I changed it to this and now it works:
<permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Can you not use uses-permission
to check permissions at runtime? Do I have to change all my uses-permission
to permission
in my app to make it work checking permissions at runtime in API 23+?
EDIT: the error I am getting in Android Studio is:
Cannot resolve symbol 'READ_EXTERNAL_STORAGE'
Ok I figured out what the problem was:
I was using
int result = ContextCompat.checkSelfPermission(this, com.mypackage.myapp.Manifest.permission.READ_EXTERNAL_STORAGE);
What I needed was:
int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE);
So it looks like using auto import in Android Studio was a bad idea lol.
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