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
andWRITE_EXTERNAL_STORAGE
permissions.
(https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions)
The new permissions are:
READ_MEDIA_IMAGES
READ_MEDIA_VIDEO
READ_MEDIA_AUDIO
But how do I 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 focuses 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 unsure about WRITE_EXTERNAL_STORAGE
permission for other document types besides videos, images and audio.
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).