Red Panda Apps logo 3D Printing Other Projects About Me

All About Storage

(At least I hope it's all)


  • All rules should apply to all App Inventor platforms
  • All built-in procedures will overwrite folders and files if they already exist
  • A / (forward slash) before the actual file name accesses the sdcard, // (two slashes) access the app's asset folder, if the file starts without a slash, you access the apps data folder
  • The companion is a special case where the files are written to the sd card (for easier debugging). The file path is /AppInventor/assets/ for assets and /AppInventor/data/ for the data folder
  • You can access files with the absolute filepath (starting with file:///)
  • There are also other ways to access specific folders of the phone, e.g. content://media/external/images/media accesses the images in the gallery
  • A link to a file on the internet is also a valid address
  • It is currently not possible to store files in the app's asset folder
  • To display files in the WebViewer, you have to set the URL to the URI of the file
  • The asset folder has an URI called file:///android_asset/
  • The data folder should have the URI file:///data/user/0/{packagename}/files/. It might not be the same for everyone, we'll have to do some research
  • It is possible to create folders. /new_folder/filename will create the folder new_folder on the sd card and will put the file filename in it. Though, I'm not able to reproduce that
  • If the folder starts with a . (dot), the folder will be hidden, i.e. invisible for non-root users
  • You can also set the url of the WebViewer to data:text/html,{html formatted text} to load the content of a html file into the webviewer. This is especially useful in combination with the ReadFrom file block

The solution (deprecated)

I finally found a way to make this possible. Assuming

  1. you want to read/write files and you want to display them in the webviewer,
  2. you don't want to store data on the sd card, because every phone treats external storage differently and you don't want your files be accessible from the outside
  3. and there is no URI for the data folder of the app,
there is only one way to do it:
  1. Read the content of the file
  2. Set the WebViewer.Url to join "data:text/html," "[content of the file]"
  3. Append something by appending it to the file while setting WebViewer.Url to join get WebViewer.current Url "new content" (The File.Got Text event provides the text)
  4. Adding css style is only possible by adding tags between data:text/html, and the actual content
I think it could also b possible with JavaScript in the document, but this is very inconvenient.

Resources

The post that started it all
The File component
Accessing images and sounds (not up to date)
Where Android apps store data