File
Definition
Non-visible component for storing and retrieving files. Use this component to write or read files on the device.
The exact location where external files are placed is a function of the value of the Scope
property, whether the app is running in the Companion or compiled, and which version of Android the app is running on.
Because newer versions of Android require files be stored in app-specific directories, the DefaultScope
is set to App
. If you are using an older version of Android and need access to the legacy public storage, change the DefaultScope
property to Legacy
. You can also change the Scope
using the blocks.
Below we briefly describe each scope type:
- App: Files will be read from and written to app-specific storage on Android 2.2 and higher. On earlier versions of Android, files will be written to legacy storage.
- Asset: Files will be read from the app assets. It is an error to attempt to write to app assets as they are contained in read-only storage.
- Cache: Files will be read from and written to the app’s cache directory. Cache is useful for temporary files that can be recreated as it allows the user to clear temporary files to get back storage space.
- Legacy: Files will be read from and written to the file system using the App Inventor rules prior to release nb187. That is, file names starting with a single
/
will be read from and written to the root of the external storage directory, e.g.,/sdcard/
. Legacy functionality will not work on Android 11 or later. - Private: Files will be read from and written to the app’s private directory. Use this scope to store information that shouldn’t be visible to other applications, such as file management apps.
- Shared: Files will be read from and written to the device’s shared media directories, such as
Pictures
.
Note 1: In Legacy mode, file names can take one of three forms:
- Private files have no leading
/
and are written to app private storage (e.g., “file.txt”) - External files have a single leading
/
and are written to public storage (e.g., “/file.txt”) - Bundled app assets have two leading
//
and can only be read (e.g., “//file.txt”)
Note 2: In all scopes, a file name beginning with two slashes (//
) will be interpreted as an asset name.
Properties
- DefaultScope
- Specifies the default scope for files accessed using the File component. The App scope should work for most apps. Legacy mode can be used for apps that predate the newer constraints in Android on app file access.
- ReadPermission
- A designer-only property that can be used to enable read access to file storage outside of the app-specific directories.
- Scope
- Indicates the current scope for operations such as ReadFrom and SaveFile.
- WritePermission
- A designer-only property that can be used to enable write access to file storage outside of the app-specific directories.