How do you get a list of nonmedia files with component "call file1.ListDirectory.."?

I can make a list of files from a (shared) directory with images.
But I can't from a shared directory (/Documents/) with textfiles.
Do I have to set special permissions. (I tried persmission readExternalStorage but that does not work)
Or Is there a another way to do that?
I can find some older posts about it but not anything that works.
I have made test blocks and only the directory of Pictures gives a list of files.
The default Filescope is set to Shared. (Also tried Legacy but that does not work either)
I tried both "Documents/" and "/Documents/" and the full path "file:///storage/emulated/0/Documents" and /storage/emulated/0/Documents" and some other variants.

To read non media files, whiich are not owned by your app, you have to use SAF, see also Some basics on Android storage system

Taifun

Ok thanks Taifun.

Depending on what you want to do, you also can try the filepicker...

http://ai2.appinventor.mit.edu/reference/components/media.html#FilePicker

Taifun

"How do you get a list of nonmedia files with component "call file1.ListDirectory.."?"

ThanksTaifun,
I just want to make a list of all files in a directory in /Documents (with maximum of 8) and use the names of these textfiels as a name of a category. That category uses that same textfile as input for showing the words in the app. So the app has to have read access to the textfile too.

I am making an app for people with braindamage whome has to learn to speak again.
They can choose from different categories.
Each category is a textfile with words. One word on each line.
To learn new words the catogories changes from time to time.
To make it easier and to keep it free of charge for he people helping the patients they can make these textfiles themselves and upload them to the phone.
The app reads the list of files in the directory and makes the new categories.

Unless the app is to be published on the Play Store, I suggest (to make it as easy as possible for everyone involved) that MANAGE_EXTERNAL_STORAGE permission (AllFilesPermission) is requested and granted. This ensures that you have complete access to all directories on the device and all file types (including non-media files).

See here:

Thank you Anke,
I will study your guide first and then will try to implement.
Joost.

It's really quite simple. (As I said, if the app is to be published in the Play Store, Google will probably not allow this permission.)

Thank you. No I won't publish it in Play Store.

I finally made it working.
The request and grant manage_external_strorage was indeed quit simple with your extension and examples.
But after solving that, the app couldn't read the textfiles with the procedure "call File1.readFrom.."
Giving me the error 908 The permission READ_EXTERNAL_STORAGE has been denied.
So I remembered you talking about your extension MFile in a post.
So I tried that and that worked.
First I was struggling with the right format of the pathnames but after some trial and error I managed.
So now I can go on and implement it in my app.

Thank you for your help and extensions.

1 Like

Yes, this is a bug with the File component on Android 13+ that I already mentioned 8 month ago. It should have been fixed long ago. @ewpatton

Until then you must use the MFile extension on Android 13+.


In your Screen1.Initialize event it should be:
.SdKVersion ≥ 30 (≥ Android 11).

Before Android 11, you can still request WRITE_EXTERNAL_STORAGE to save and read any file (media or non-media files) anywhere in the external storage. READ permission is then no longer needed because WRITE also implicitly grants READ permission.

Ok thank you I will change that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.