How to read a file (JSON) from the phone's memory into the AI2 application

Disclaimer: This topic may not be new to the forum; I have seen many posts about reading files, but these options did not work for me and were quite complex and extensive. Through experimentation, I found a successful combination that I would like to share with other users. So consider this my report on solving my own problem. Best of luck to everyone!

In my program, the data necessary for the application to work was stored in a JSON file, and I needed to access it (in the phone's memory) from the application. Using the standard File module, DataFile, and other file managers did not work. Error 908 occurred: The permission READ_EXTERNAL_STORAGE has been denied.

To retrieve the file from the phone's memory and work with it, you will need user modules (EFile and JewelFilePicker). You can install them using the links below (format .aix). In the AppInventor editor menu, in the Extension section, click Import Extension and specify the path to the downloaded file.

EFile (GitHub - vknow360/EFile: A modified version of File component (For MIT AI2 and its distros)) (EFile : Only asks for permissions when required - Extensions - Kodular Community) – equivalent to the standard File module with read and write permissions

JewelFilePicker ([Free] JewelFilePicker Extension : Pick Any Type Of File From Storage) – select a file from storage

The first entry is made when using the file manager (JewelFilePicker), which I have linked to a button press. The path to the file is passed to the user module (EFile), which has no restrictions on reading and writing from internal storage. I use the TinyDB database (optional) to store the selected file path, but you can do without it by passing the path directly or saving it to a global variable. On new launches, the last saved file path is automatically added during application initialization.

As a result, without additional program settings or phone modifications, I was able to access JSON files in the phone's memory and on the SD card from anywhere. Tested on a Xiaomi POCO M5s phone (non-root).

*Added a screenshot of the most minimal implementation (at the bottom of the page)

You could also try pure SAF:

1 Like