Skip to first unread message

Taka

unread,
Jul 18, 2014, 10:53:52 PM7/18/14
to mitappinv...@googlegroups.com
Hello !   Please help me to find my file.

When I run the app in emulator mode on my phone, the file named, for example, "ABC.txt" is saved into  sdcard/AppInventor/data.  I can find it and read it on my Android phone.  Here, "emulator mode" I mean is to run the app on my phone by selecting "Connect >> AI Companion" on my PC and scan the 2D bar code by my phone.   It is not to run the emulator on the PC.

However, once I create apk file and install it into my phone, the file created by my app is not saved to the same location.  Even I search entire memory area including external sdcard, I couldn't find it. On the other hand, the app still can save and read data by using the file name "ABC.txt", I think the file exist somewhere in my phone.  It could be in the directory the Android 4.2 doesn't allow access by user.....

Based on the info in this forum, I have changed the file name like below but non of them works. When I change the file name, I just have an error message and data save or read fail.

 "//mnt/sdcard/AppInventor/data/ABC.txt", "file:///mnt/sdcard/AppInventor/data/ABC.txt", "mnt/sdcard/AppInventor/data/ABC.txt"

Then, I replaced "mnt/sdcard" with "emulator/storage/0"  but not work too.


Please let me know 1) where is my file and 2) how can I change the data saving location to my accessible folder.

Stephen Zipprich

unread,
Jul 19, 2014, 12:42:05 AM7/19/14
to
Please let me know 1) where is my file

I believe that when you are saving files with App Inventor, because saving to the SD card is not supported, it saves them to the assets of the app, which is not accessible.

If the app is packaged on the phone, and you save a file to the assets, or load a file into the project as a media file, you need to use something similar to this picture to access the file

If you are developing with the phone/emulator but haven't packaged the app yet and the file you're reading from is uploaded to the project as a media file, you need to use this as your editing path

Therefore, if you upload a file as media into your app and you need to test it during development and then want to be able to access it once you've packaged the APK, you would want to do a boolean value check like this:

Once you're ready to package the app, change the global variable to false and you're good to go.


and 2) how can I change the data saving location to my accessible folder.

App Inventor does not yet support saving to the SD card. 

SteveJG

unread,
Jul 19, 2014, 8:55:29 AM7/19/14
to
@Stephen  , regarding   "App Inventor does not yet support saving to the SD card. "   According to the File documentation tool, AI2 is supposed to save to the SD card.  See the line in the documentation highlighted in red text.  Is the File control documentation wrong or is there a bug or what do you suppose?  We need to sort this out.  (see below). I think working with text files and the File component works differently than you described..which is the case when using other components.

@ Taka  ... you probably can not find the file, because as Stephen indicated, saving without a \ sends ABC.txt to storate within the app.  The documentation says to do this: "  /myFile.txt will write the file to /sdcard/myFile.txt".; so when you build the apk, you code should  look like this: /ABC.txt   if you want to store ABC.txt  to the sd card.     

  I think if you do this:  /TakasFile/ABC.txt  the file will be stored to a new folder called TakasFile on the sdcard    and if you have a FILE listing app on your device,  it should find that stored file  located at   /sdcard/TakasFile/ABC.txt   .or something similar.

I am doing some experimenting.   I do not know if Taka's issue is a bug in the File control, an issue with his Android version or a problem with his hardware.

Try what I recommended  Tka and let us know what you discover please.    In the mean time,   I am going to do some experiments.

Thanks for your notes guys.

Regards,
Steve


File

Non-visible component for storing and retrieving files. Use this component to write or read files on your device. The default behaviour is to write files to the private data directory associated with your App. The Companion is special cased to write files to /sdcard/AppInventor/data to facilitate debugging. If the file path starts with a slash (/), then the file is created relative to /sdcard. For example writing a file to /myFile.txt will write the file in /sdcard/myFile.txt.

Properties

none

Events

GotText(text text)
Event indicating that the contents from the file have been read.

Methods

AppendToFile(text text, text fileName)
Appends text to the end of a file storage, creating the file if it does not exist. See the help text under SaveFile for information about where files are written.
Delete(text fileName)
Deletes a file from storage. Prefix the filename with / to delete a specific file in the SD card, for instance /myFile.txt. will delete the file /sdcard/myFile.txt. If the file does not begin with a /, then the file located in the programs private storage will be deleted. Starting the file with // is an error because assets files cannot be deleted.
ReadFrom(text fileName)
Reads text from a file in storage. Prefix the filename with / to read from a specific file on the SD card. for instance /myFile.txt will read the file /sdcard/myFile.txt. To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes). If a filename does not start with a slash, it will be read from the applications private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.
SaveFile(text text, 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 programs 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. Note that this block will overwrite a file if it already exists. If you want to add content to a file use the append block.

Taka

unread,
Jul 19, 2014, 9:45:29 PM7/19/14
to mitappinv...@googlegroups.com
Thanks Stephen and Steve,

Now I could save the file into accessible area of my sdcard !!

I found what was wrong with me. I included FULL path, such as "/mnt/sdcard/AppInventor/data/ABC.txt" or "/emulator/storage/0/AppInventor/data/ABC.txt"

Instead, as Steve shows, I changed it to "/Takafile/ABC.txt"  or  "/AppInventor/data/ABC.txt" then both work.

Thanks for your prompt advises.

Taka
Reply all
Reply to author
Forward
0 new messages