App Inventor and Java


Save a text file to SD card using the Activity Starter calling a Java app

Note: with the new File component, which has been introduced in release nb133 on May, 18th 2014, this workaround is now obsolete. Thank you MIT!

Patrick Doyle demonstrated here how to save text to a file on SD card without internet connection. I now put together a runnable Java apk using the source from Patrick and a small App Inventor project to test it. Thank you Patrick!

Version 2: Now you can configure the target directory in the Java app. And in case the directory does not exist, it will be created now.

Note: This example works only, if the Java app savetosd.apk is installed on your device.

I now also can offer Version 3 of SaveToSD. There it is possible to pass the filename from App Inventor to Save To SD. The file will be saved in the background without displaying the "Enter File Name" box.

Also you might be interested in a php solution which requires internet connection. The php example you can find here.

For questions about App Inventor,
please ask in the App Inventor community.Thank you.

Screenshots

App Inventor blocks

Questions and Answers

Q1: I am wondering if I can use SaveToSD to append a row to an existing CSV file on the SD card from within App Inventor.
A: Sorry, I'm currently not able to add that feature into SaveToSD. However you have the following possibilities:
1. store the complete csv additionally as multiple list in TinyDB. Then you can add new rows easily with the "add items to list" block and save each time the complete csv on SD card, or
2. first try to read that file with the How to import a multiline csv file on first run of the app example. You can modify the HTML file to read from the location you need. Then just join the result you get with the new data and save it with SaveToSD.

Q2: I did not know that I could access the TinyDB on the SD card directly to make a copy of the csv list. How do I do that?
A: Normally inside App Inventor you are working with lists or list of lists using the list blocks. To save a csv file, you just convert the list with the "list to csv table" block into the csv format and pass that to SaveToSD.

Q3: If I store the data within a list and click the save button it will save the data to the CSV file. If I then append further data to the list and save again, will the SaveToSD overwrite the existing file with all the data or create a new CSV file?
A: If you save again, the file will be overwritten in case it already is there.

Q4: It seems that your present version of savetosd requires the User to tap a "save" button, plus it displays a dialog with other options. What I'm looking for is a version of savetosd that would let me supply a large text string to save, to a file that is also supplied by the front-end as a parameter. So, no dialogs, just a hidden helper-app.
A: This is already available, see Version 3 of SaveToSD.

Q5: Is it possible to integrate "Java app savetosd3.apk" in my app, so that a unique download and installation is needed? Otherwise it will need to do 2 installation: savetosd3.apk and my app.
A:Save To SD is a Java app and therefore it is not possible to integrate it into your App Inventor app. You have to do 2 installations therefore. Alternatively use the php solution, which requires internet connection.

Download


Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!

Donation amount:

or donate some mBTC to Bitcoin Address:
1Jd8kXLHu2Vkuhi15TWHiQm4uE9AGPYxi8
Bitcoin

Thank you! Taifun
 

Back to top of page ...

Creative Commons License
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.


Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact