Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime permission check API 23+: Cannot resolve symbol 'Manifest.permission.READ_EXTERNAL_STORAGE'

Tags:

android

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'

like image 440
Micro Avatar asked Dec 01 '22 13:12

Micro


1 Answers

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.

like image 83
Micro Avatar answered Dec 15 '22 17:12

Micro