How to access non-media & media files on Android 11+

Access to non-media files on Android 11+

On Android 11+, non-media files (like txt, pdf, csv, ...) can be accessed
if and only if

  1. the text files are in the → ASD or in the → Private dir (i.e. were saved there), or
  2. the text files are in one of the Shared folders /Documents or /Download and
    these files were created by the app itself, or
  3. SAF is used, or
  4. MANAGE_EXTERNAL_STORAGE* permission is requested and granted.

*` This is not really an option, because an app that requests this permission will (most likely) not be allowed in Google's Play Store.

Note: Of course, all files in the assets can be read. However these are read only.

Access to media files on Android 11+

Without READ permission, media files (like jpg, png, mp3, mp4, ...) can be read on Android 11+
if and only if

  1. these files are located in one of the Shared folders (/Pictures, /DCIM, /Documents, /Download, /Music, /Movies) and were created by the app itself, or
  2. these are in the ASD or
  3. these are in the Private directory.

With READ permission, all media files can be read from all areas of the external storage (also from the root dir).

Without WRITE permission, media files can be saved on Android 11+
if and only if

  1. these are stored in the ASD or
  2. these are stored in Private dir or
  3. these are stored in one of the Shared folders.

The Private directory is in the internal storage:

/data/user/0/<packageName>/files/

Note: Since WRITE_EXTERNAL_STORAGE permission no longer exists on Android 11+, without MANAGE_EXTERNAL_STORAGE there is no way to save files outside of the ASD, Private dir or Shared folders. Or you must use SAF.

For more details see also here:

12 Likes

Dear Anke,

Thank you so much for your reply, I tried different paths for the file and now it is finally working.
I'm very thankful for your help, I would not have been able to solve it without you and all your device.

Thank you so much!! This app should help to name the photos for bat roosts. So you actually made a contribution to bat conservation :wink:

2 Likes

So if you use MANAGE_EXTERNAL_STORAGE while uploading app to play store it is asking for details. why we are using this functionality to for usage of MANAGE_EXTERNAL_STORAGE. What to mention there i am using this permission for pdf files getting. can you anyone specify some details for using this permission.

Hello,

I saw that the /Download folder could only be accessed if the file had been created from the application.
Here is my problem:
My application must be able to be downloaded to be installed, and use a .csv file created separately.
It will be students who will do the manipulations, and I can't ask them to go to the folders and move the .csv file to the right place (which will be different from one phone to another), everything would have to be automatique.
Is there a solution?

Save the CSV in the ASD (App Specific Directory) instead. If the CSV is a download, you can use Anke's extension version 2:

... by whom, the app or is the student creating this file outside of the app?

... within / through the app?

I create the .csv file, students must download it before using the application.

By default, the download is done in the /Download folder of the smartphone, and having the students move it will be very complicated, it seems to me.

So the CSV file is downloaded via the app?
If so, then why move it to another location?

Students will need to upload two files:

  • the .apk to install the application
  • the .csv that the application can use it

or download ?

@tantangel I think we're leaving the topic here.
So open a new topic and ask your questions there precisely.

yes, sorry...

A post was merged into an existing topic: [Free] File Picker Extension - Pick File From Storage (2.1.6)

Hello:
I'm with a problem reading a txt or csv archive. I need that the app read one of these archives, that can be in one directory (Documents/Download or other created in /storage/emulated/0/ . The problem is that this archive is writen ther by a NFC card, so as it hasnt been created by the app, the app doesnt read it. And for the NFC is not possible to write the txt archive into ASD directory o Private...
What can be a solution for that?

If it is (as you say) in the root directory of the external storage or in /Download, there is no other solution than to declare the MANAGE_EXTERNAL_STORAGE permission in the Manifest. However, unless you can explain why this is a core part of your app, the app will most likely not be approved by Google in the Play Store.

If the file is in /Documents or another directory (not mentioned above), there is no problem using SAF.

Thanks for your answer. I've read deeply your post, so I used ASF but couldn't access to the data inside the archive. As you said it could be the best wayt to avoid Play Store problems.
NFC copy a file (registro.txt with CSV as data) into Documents/data/registro.txt,

I simplify the code to this function:

blocks

But I get "No content provider: /Documents/datos/registro.txt" as an answer instead of the data.
I had 'Legacy' in screen properties in orther to reach Documents/data directory. (Is that the correcto option?)

What i'm not doing well?

Sorry not ASF --> SAF

You need to use OpenSingleDocument block first, then in GotUri event, ReadFromFile.
Any way read all the posts in the thread of SAF extension, since for how to use SAF it's off-topic.

1 Like

Try this: