56

The behaviour changes for Android 13 mention this:

If your app targets Android 13, you must request one or more new permissions instead of the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions.

(https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions)

The new permissions are:

  • Images and photos: READ_MEDIA_IMAGES
  • Videos: READ_MEDIA_VIDEO Audio
  • Audio files: READ_MEDIA_AUDIO

But how to handle this, if I e.g. need to read PDF files from an arbitrary folder? There's no permission like READ_MEDIA_DOCUMENT or something like that. What about other file types, which are not images, videos or audio? Can I still use READ_EXTERNAL_STORAGE permission for them?

I didn't find any information about this in the official documentation, but to be honest the documentation is focusing on media files only without any word about other file types (https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions).

I am also not sure about WRITE_EXTERNAL_STORAGE permission for other document types beside of videos, images and audio.

Christopher
  • 9,682
  • 7
  • 47
  • 76
  • That's one useful information: https://crast.net/19777/this-is-how-permissions-change-in-android-13-notifications-nearby-devices-music-and-more/ – Christopher Jul 12 '22 at 14:01
  • 2
    Do you find any way to deal with this issue? I facing the same problem that I can request READ_EXTERNAL_STORAGE permission anymore on android 13, so I can't allow my user to pick their pdf/excel/... files :D – Hung Nguyen Aug 22 '22 at 02:25
  • 2
    @HungNguyen: I think using the corresponding APIs here is the way to go: https://developer.android.com/training/data-storage/shared/documents-files – Christopher Aug 22 '22 at 07:52
  • @Christopher "To support media file access on devices that run Android 9 (API level 28) or lower, declare the READ_EXTERNAL_STORAGE permission and set the maxSdkVersion to 28." Very funny... :( – The incredible Jan Apr 12 '23 at 06:15
  • You can just fire an Intent of type ACTION_OPEN_DOCUMENT to select document files. For other type of media files, you can either go with PhotoPicker or granular permissions. Check this: https://codewithninad.com/accessing-android-storage-on-android-13-above/ – N-JOY Aug 14 '23 at 08:19

2 Answers2

38

According to documentation (https://developer.android.com/training/data-storage/shared/media#storage-permission):

No permissions needed if you only access your own media files On devices that run Android 10 or higher, you don't need any storage-related permissions to access and modify media files that your app owns, including files in the Media Store. Downloads collection. If you're developing a camera app, for example, you don't need to request storage-related permissions because your app owns the images that you're writing to the media store.

From android 10 you can not to ask permissions to get files from storage. Works perfectly with all kinds of files (pdf, excel...) on my app on android 13 without any permissions. So you just need to ask READ_EXTERNAL_STORAGE permission for SDK, less than android 10.

But if you need special files (for example which was created by Instagram app but not stored in usual storage) you should ask for permission from your list.

Also look for types of Media storage: https://developer.android.com/reference/android/provider/MediaStore

About WRITE_EXTERNAL_STORAGE - you don`t need it since sdkVersion=29

EDIT: Was rewriting my app and want to add something:

It depends on what your app needs to do, but I have removed all kinds of storage permissions (only WRITE_EXTERNAL_STORAGE left for SDK less than 29) from my app, and just use ACTION_OPEN_DOCUMENT, ACTION_OPEN_DOCUMENT_TREE to have access for all kind of files (but not for system folders, ACTION_OPEN_DOCUMENT_TREE also have no access for download folder).

Zain
  • 37,492
  • 7
  • 60
  • 84
Alexander
  • 536
  • 4
  • 6
  • 2
    So in conclusion, if I set `compileSdkVersion` to 33 I still need to get READ_EXTERNAL_STORAGE for android 10 and below, even if I want access to my application files. Also WRITE_EXTERNAL_STORAGE is not needed as long as I'm writing to my own application files. Am I right? – Mohammad Dec 19 '22 at 12:06
  • did you get an answer to your above question @Mohammad? – Gigalink Dec 30 '22 at 10:23
  • 1
    yes. if you set `compileSdkVersion` to 33, you should **only** get READ_EXTERNAL_STORAGE for android 10 and below. otherwise, your request permission will always fail. WRITE_EXTERNAL_STORAGE is also deprecated and you should remove It from your manifest. If you need to access non-your-application files, then you have to get related permissions like READ_MEDIA_VIDEO for videos. other ones are listed in the android-permission documentation. – Mohammad Dec 30 '22 at 19:17
  • Thanks, Alexander and Zain for your answers and edits. It really helps me. – Milan Sheth Feb 17 '23 at 17:14
  • App can read and display all image if i install the internal beta test but if i update the playstore app i am able to read image size but width height and image cannot be display because of permission error... details in https://stackoverflow.com/questions/75533255/android-13-give-permission-issue-after-updating-internal-beta-testing-to-the-pla – Anjan Thakuri Feb 22 '23 at 13:35
  • 1
    Without the download folder this doesn't help much. My app works with PDF files and images. I used to be able to download a PDF or image file. Then tap it, and "Share". My app is listed among the sharable apps. This no longer works. Other sharable apps do so something must be able to get to the downloads folder. – Paul Mar 30 '23 at 21:34
  • @Mohammad There are no READ_MEDIA_PDF or READ_MEDIA_XLS. Our users should be able to edit all documents they want and attach them to data records in our app. – The incredible Jan Apr 12 '23 at 06:24
  • Not working for accessing PDF files – Angel Jun 09 '23 at 04:20
12
On Android 13 the READ_EXTERNAL_STORAGE has been replace by READ_MEDIA_IMAGES and READ_MEDIA_VIDEO

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
naveed ahmed
  • 161
  • 1
  • 6
  • 1
    That's not work for me. Api 33 don't work. I use dexter for runtime permision to read images `` But not work in Api33. – Ahmet Yılmaz May 17 '23 at 10:58
  • Alexander's answer I think more correct, to use READ_EXTERNAL_STORAGE no need add another permission. until you need to pick specific file for images / video. – Zainal Fahrudin Jul 14 '23 at 07:30