Storage

« Back to index

Storage

Table of Contents:

CloudDB

The CloudDB component is a Non-visible component that allows you to store data on a Internet connected database server (using Redis software). This allows the users of your App to share data with each other. By default data will be stored in a server maintained by MIT, however you can setup and run your own server. Set the RedisServer property and RedisPort property to access your own server.

Properties

ProjectID
Gets the ProjectID for this CloudDB project.
RedisPort
The Redis Server port to use. Defaults to 6381
RedisServer
The Redis Server to use to store data. A setting of “DEFAULT” means that the MIT server will be used.
Token
This field contains the authentication token used to login to the backed Redis server. For the “DEFAULT” server, do not edit this value, the system will fill it in for you. A system administrator may also provide a special value to you which can be used to share data between multiple projects from multiple people. If using your own Redis server, set a password in the server’s config and enter it here.
UseSSL
Set to true to use SSL to talk to CloudDB/Redis server. This should be set to True for the “DEFAULT” server.

Events

CloudDBError(message)
Indicates that an error occurred while communicating with the CloudDB Redis server.
DataChanged(tag,value)
Indicates that the data in the CloudDB project has changed. Launches an event with the tag that has been updated and the value it now has.
FirstRemoved(value)
Event triggered by the RemoveFirstFromList function. The argument value is the object that was the first in the list, and which is now removed.
GotValue(tag,value)
Indicates that a GetValue request has succeeded.
TagList(value)
Event triggered when we have received the list of known tags. Run in response to a call to the GetTagList function.

Methods

AppendValueToList(tag,itemToAdd)
Append a value to the end of a list atomically. If two devices use this function simultaneously, both will be appended and no data lost.
ClearTag(tag)
Remove the tag from CloudDB.
CloudConnected()
Returns true if we are on the network and will likely be able to connect to the CloudDB server.
GetTagList()
Asks CloudDB to retrieve all the tags belonging to this project. The resulting list is returned in the event TagList.
GetValue(tag,valueIfTagNotThere)
GetValue asks CloudDB to get the value stored under the given tag. It will pass the result to the GotValue will be given.
RemoveFirstFromList(tag)
Obtain the first element of a list and atomically remove it. If two devices use this function simultaneously, one will get the first element and the the other will get the second element, or an error if there is no available element. When the element is available, the FirstRemoved event will be triggered.
StoreValue(tag,valueToStore)
Asks CloudDB to store the given value under the given tag.

DataFile

Component for DataFile

Properties

ColumnNames
Retrieve the column names of the currently loaded Source file. For CSV files, this will return a List of entries in the first row. For JSON files, this will return a List of keys in the JSON object.
Columns
Retrieve a List of columns of the currently loaded Source file.
LegacyMode
Allows app to access files from the root of the external storage directory (legacy mode). Starting with Android 11, this will no longer be allowed and the behavior is strongly discouraged on Android 10. Starting with Android 10, App Inventor by default will attempt to store files relative to the app-specific private directory on external storage in accordance with this security change.

Note: Apps that enable this property will likely stop working after upgrading to Android 11, which strongly enforces that apps only write to app-private directories.

Rows
Retrieve a List of rows of the currently loaded Source file.
SourceFile
Sets the source file to parse data from, and then parses the file asynchronously. The results are stored in the Columns, Rows and ColumnNames properties. The expected formatting of the file is either the CSV or JSON format.

Events

None

Methods

ReadFile(source)
Indicates source file to load data from.The expected format of the contents of the file are either CSV or JSON.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.The results of the reading are stored in the Rows, Columns and ColumnNames properties of the component.

File

Non-visible component for storing and retrieving files. Use this component to write or read files on the device. The default behavior is to write files to the private data directory associated with the app. The Companion writes files to /sdcard/AppInventor/data for easy 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

LegacyMode
Allows app to access files from the root of the external storage directory (legacy mode). Starting with Android 11, this will no longer be allowed and the behavior is strongly discouraged on Android 10. Starting with Android 10, App Inventor by default will attempt to store files relative to the app-specific private directory on external storage in accordance with this security change.

Note: Apps that enable this property will likely stop working after upgrading to Android 11, which strongly enforces that apps only write to app-private directories.

getSDCardPath
Property for getSDCardPath

Events

AfterFileSaved(fileName)
Event indicating that the contents of the file have been written.
GotText(text)
Event indicating that the contents from the file have been read.

Methods

AppendToFile(text,fileName)
Appends text to the end of a file. Creates the file if it does not already exist. See the help text under SaveFile for information about where files are written. On success, the AfterFileSaved event will run.
Delete(fileName)
Deletes a file from storage. Prefix the fileName with / to delete a specific file in the SD card (for example, /myFile.txt will delete the file /sdcard/myFile.txt). If the fileName does not begin with a /, then the file located in the program’s private storage will be deleted. Starting the fileName with // is an error because asset files cannot be deleted.
ReadFrom(fileName)
Reads text from a file in storage. Prefix the fileName with / to read from a specific file on the SD card (for example, /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 application’s private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.
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.

Note that this block will overwrite a file if it already exists. If you want to add content to an existing file use the AppendToFile method.

SensorDB

Component for SensorDB

Properties

ArchivePeriold
Current period of the schedule archive task
CurrentActiveSensors
Returns the active sensors.
DBName
Property for DBName
ExportFolderPath
Property for ExportFolderPath
ExportFormat
Property for ExportFormat
ScheduleArchiveEnabled
Indicates whether the schedule archive task is currentenabled.
ScheduleClearBackupEnabled
Indicates whether the schedule clear db bacup task is currently enabled
ScheduleClearBackupPeriod
Current period of the schedule clear backup task
ScheduleExpoertPeriod
Current period of the schedule export task
ScheduleExportEnabled
Indicates whether the scheduled export task is currentenabled.

Events

FinishedInitServiceValues()
Indicates that SensorDB is bound to SensorDBPipeline and re-initialize values from the pipeline e.g. archive_period, export_period, clearbackup_period, ..etc. App Inventor’s user should use this event to update UI that needs values from the background service

Methods

AddSensorCollection(sensorName,period)
Add sensor colleciton task for a specific sensor with specified period (in seconds)
Export(format)
Export the Sensor Database (SensorData as the name for the sqlite db on Android) as csv file(s) or JSON file(s). Each type of sensor data in the database will be export it as one file. The export path is under SDcard/packageName/export/
ForceKill()
(Testing) force Stop funfManager
RemoveSensorCollection(sensorName)
Remove data colleciton task of a specific sensor
ScheduleArchive(period)
Enable archive schedule task with specified period in seconds
ScheduleClearBackup(period)
Enable clear db backup schedule task with sepcified period in seconds
ScheduleExport(period)
Enable export db schedule task with specified period in seconds
StopClearDbBackup()
Disable clear backup task
StopScheduleArchive()
Discable archive scheduled task
StopScheduleExport()
Discable export scheduled task
UpdateSensorCollection(sensorName,period)
Update the period of sensor colleciton task of a specific sensor
getAvailableSensors()
Return available names of the avaiable sesnors for data collection

TinyDB

TinyDB is a non-visible component that stores data for an app.

Apps created with App Inventor are initialized each time they run. This means that if an app sets the value of a variable and the user then quits the app, the value of that variable will not be remembered the next time the app is run. In contrast, TinyDB is a persistent data store for the app. The data stored in a TinyDB will be available each time the app is run. An example might be a game that saves the high score and retrieves it each time the game is played.

Data items consist of tags and values. To store a data item, you specify the tag it should be stored under. The tag must be a text block, giving the data a name. Subsequently, you can retrieve the data that was stored under a given tag.

You cannot use the TinyDB to pass data between two different apps on the phone, although you can use the TinyDB to share data between the different screens of a multi-screen app.

When you are developing apps using the AI Companion, all the apps using that Companion will share the same TinyDB. That sharing will disappear once the apps are packaged and installed on the phone. During development you should be careful to clear the Companion app’s data each time you start working on a new app.

Properties

Namespace
Namespace for storing data.

Events

None

Methods

ClearAll()
Clear the entire data store.
ClearTag(tag)
Clear the entry with the given tag.
GetTags()
Return a list of all the tags in the data store.
GetValue(tag,valueIfTagNotThere)
Retrieve the value stored under the given tag. If there’s no such tag, then return valueIfTagNotThere.
StoreValue(tag,valueToStore)
Store the given valueToStore under the given tag. The storage persists on the phone when the app is restarted.

TinyWebDB

The TinyWebDB component communicates with a Web service to store and retrieve information. Although this component is usable, it is very limited and meant primarily as a demonstration for people who would like to create their own components that talk to the Web. The accompanying Web service is at (http://tinywebdb.appinventor.mit.edu). The component has methods to store a value under a tag and to retrieve the value associated with the tag. The interpretation of what “store” and “retrieve” means is up to the Web service. In this implementation, all tags and values are strings (text). This restriction may be relaxed in future versions.

Properties

ServiceURL
Specifies the URL of the Web service. The default value is the demo service running on App Engine.

Events

GotValue(tagFromWebDB,valueFromWebDB)
Indicates that a GetValue server request has succeeded.
ValueStored()
Event indicating that a StoreValue server request has succeeded.
WebServiceError(message)
Indicates that the communication with the Web service signaled an error.

Methods

GetValue(tag)
GetValue asks the Web service to get the value stored under the given tag. It is up to the Web service what to return if there is no value stored under the tag. This component just accepts whatever is returned. The GotValue event will be run on completion.
StoreValue(tag,valueToStore)
Sends a request to the Web service to store the given valueToStore under the given tag. The ValueStored event will be run on completion.