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
How to request and grant MANAGE_EXTERNAL_STORAGE permission
File - readfrom filename dont work
MFile - a modified version of Sunny's `EFile` extension - Shared folders - storage permissions - Android 11+
Error 2102 (file name) could not be opened
Search new photo and upload FTP
How do you write to Internal Storage?
Give some tips to create an app that has options to get ecommerce selling data like 1) Product Name, 2) Product image, 3) Price etc
File found - file not found
MFile - a modified version of Sunny's `EFile` extension - Shared folders - storage permissions - Android 11+
Unresolved issue with Android 13+ permissions
Crear 2 archivo en una sola carpeta / Create 2 file in a single folder
Non riesco a salvare file e ad allegare la lista creata
Activity Starter pdf open failed
Taifun Camera Extension?
Taifun Camera Extension?
Save file to internal storage
App no reconoce carpetas o archivos de mi dispositivo
Attach all files from a folder to an email
I want to save a file in the desired path
Pick Pdf file on Android12
Unable to find data file
FAQ Section: Files
:stop_button: StorageAccess Extension: Simplifying Storage Permissions in MIT App Inventor
Why is it so difficult to save a CSV from a List?
Write to external storage *confused*
Permissions to /storage/emulated/0/Documents/
The application stopped running
Open gpx file in webviewer with run javascript
Assets Filepath
Options to read CSV external file into App
Media not existent on Build .apk
[FREE] ASD Downloader Extension - Download and manage files in ASD
Having trouble with my app reading files on my phone
The application stopped running
Can't Show all files from shared storage
Full path of a file
App with DB offline
Open a file in local directory ///sdcard
Can't search and save csv files? - File component - FileScope (Android11)
Listpicker to read from a txt
[Free] JewelFilePicker Extension : Pick Any Type Of File From Storage
Where are the files saved when the application is compiled?
Create My App Album
How do you get a list of nonmedia files with component "call file1.ListDirectory.."?
Use (Read, write) non media file
File reading problem with Android 11
How can i get internal storage access?
Compress the images taken by Camera
Error 908 The permission
SAF / MFile Tests
SAF / MFile Tests
I want to save a file in the desired path
Some basics about using SAF
Reading directory using saf asd or file component and get image display in canvas
Error from Companion: Font asset not found /storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/assets/default
Copying File from Download Folder to ASD
Open Failed: EACCESS with TaifunFile
MFile - a modified version of Sunny's `EFile` extension - Shared folders - storage permissions - Android 11+
Taifun file extension issue
SAF: App Inventor implementation of Storage Access Framework
How do I save a non-media file (txt, csv) in one of the Shared folders and read it on Android 11+ ( and fix beginners bugs)
Off topic discussion about storage permissions
How do you create a new file using file picker and write to it?
Dummy trying to learn phone files / folder operations
I'm having problems with the file system/file structure on Android/AI2
I'm having problems with the file system/file structure on Android/AI2
Open File Error 2102
How do you import data from file on API30, API31?
Text files saved from app on phone invisible?
Error 908 . How can I change from app to legacy?
Permission popup doesn't show up
How do I save file to phone?
Help with generating a sheet file from various labels
Listpicker filter bar
Can't write file to SHARED directories on API31 (Android 12)
MFile - a modified version of Sunny's `EFile` extension - Shared folders - storage permissions - Android 11+

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:

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: