I am trying to read image paths from the repository, and I keep getting a SecurityException here:
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=31409, uid=10053 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
I compile against api 23 and have permissions clearly indicated in my manifest as the direct child of my manifest. I also understand that in new runtime permissions, you must request permission at runtime when you want to access the repository. When I write this line, which starts checking for permission that I get, it is impossible to solve the problem in the IDE:
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
Cannot resolve character Manifest.permission.READ_EXTERNAL_STORAGE. The only Manifest.permission that I can clearly indicate in my code - Manifest.permission.C2D_MESSAGE, without receiving an error, cannot resolve the error. Is there anything else I need to compile in order to have access to other permissions in the code?
Just to be clear, this is a block of code that provides me with a SecurityException:
public List<String> getCameraImagesFull(Context context) { Cursor cursor = null; String[] star = {"*"}; ArrayList<String> result = new ArrayList<>(); cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, star, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC"); if (cursor != null) { if (cursor.moveToFirst()) { do { String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); result.add(path); } while (cursor.moveToNext()); } cursor.close(); } return result; }
this is the line that throws the exception:
cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, star, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
And here are all the permissions specified in my manifest:
<permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
I'm just wondering how I can request this permission to get image paths. It all works when I compiled against any Lollipop build, just with new runtime permissions on Marshmallow im getting SecurityExeption. Any help is appreciated, thanks in advance