Reading Files from Internal Storage

Why don't you store the file in a shared directory?
/Downloads or /Documents would be the correct place..

Taifun

1 Like

And how would I reference a shared directory such as /Downloads or /Documents?

As already said

Taifun

2 Likes

So they are interchangeable? I can use any of the 3 formats?

These questions might seem silly to you but I'm only using MIT App Inventor for a week :slight_smile:

as @Anke already tried to explain, generally they are the same, however some components require a specific format

please check the documentation for which type of path to use... for the file component just use the relative path

Taifun

2 Likes

Hi, good afternoon.

I've been trying to save the file on /Downloads, but without success.

I've tried:

/Download/test.txt
/storage/emulated/0/Download/testt.txt
file:///storage/emulated/0/Download/text.text

But nothing worked....the file names are always appended to the ASD. For instance, if the file name is
/storage/emulated/0/Download/test.txt
it will try to save on
/storage/emulated/0/Android/data/appname//storage/emulated/0/Download/test.txt

Am I doing something wrong?

Best regards,
Rui

Maybe. If you expose your blocks or post an aia example of your Project, someone can evaluate what you are doing. This discussion appears to be going in circles. :cry: Post #13 indicates this issue is solved. That isn't corrrect?

It's as simple as this:

image

This is correct to save a text file with Android > 9 in the subfolder /Download of the ASD.
But this subfolder (/Download) does not exist (in the ASD). So you must create it beforehand using e.g. the TaifunFile or FileTools extension.

1 Like

1 Like

Hi Anke,

yes, but my goal was to save it on /storage/emulated/0/Download/

Rui

This will no longer work with the coming update (targetSdkVersion = 30)
(which should actually already be available from Aug).

for me this looks correct for the current version of App Inventor, see also the documentation Storage

SaveFile( text , fileName )

Saves text to a file. If the fileName begins with a slash ( / ) the file is written to the sdcard (for example, writing to /myFile.txt will write the file to /sdcard/myFile.txt ). If the fileName does not start with a slash, it will be written in the program’s private data directory where it will not be accessible to other programs on the phone. There is a special exception for the AI Companion where these files are written to /sdcard/AppInventor/data to facilitate debugging.

is the documentation not up-to-date anymore?
probably we have to wait for the new version for storing to a shared directory again?

as far as I understand, this will still work in the new version... /Download is a shared directory, so in the new version of the file component you will have to use fileScope Shared together with the path /Download/contactos.txt, see also the design document File component - save (all types of) files in the Private dir (→ internal storage) - #8 by ewpatton

Taifun

Did you test also after building the app?
Taifun

Schön wär's. :wink:
That would be nice, but I don't think so.

Actually that's the purpose of file scope Shared...
Taifun

Saving files in the shared storage seems to be intended / to work only for media files.

@ewpatton might want to comment on this
Taifun

1 Like


See here.