SecurityException Permission Denial MediaProvider

2019-07-10 14:29发布

问题:

i am making gallery.

i got below exception

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=23769, uid=10470 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

I added permission

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"  />

in my AndroidMainfest

my code is below :

  Cursor localCursor = MediaStore.Images.Media.query(getContentResolver(), uri, mQuery);

i using nexus 5 (android ver 6.0) help!!

回答1:

The permission model changed with Android Marshmallow. You should read this https://developer.android.com/training/permissions/requesting.html article first! Most of your question will be answered.