File system access

Any files that you work with in your apps are stored in the file system on the device. Different file system locations have different permissions; in some areas, you can create new files to store your app data, while in others, your app can only read data from existing files. If you want to access your data files, you need to understand where your data files are located in the file system. The following table describes the folders that are visible in the Target File System Navigator of the Momentics IDE:

Target Folder location File Path on device Description
Developer /accounts/devuser The devuser home location to access your target system. The folder is read-only and contains your debug token.
Sandboxes /accounts/1000/appdata The location of all your application files, such as the code binaries, images, music, and documents.
Shared /accounts/1000/shared The location of shared files, such as pictures from the camera, music, and documents.
System The entire file system (/) The folders that you have access to that include resource bundles, utilities, apps that are installed on the system, and content on removable media, such as a microSD card.

To access the microSD card, you can navigate to System/sdcard/external_sd.

Before you can do any work in the file system on the device, you should make yourself familiar with the working directory. The working directory is where your application is started, and is also known as the current directory or the sandbox. UNIX-style groups and permissions govern the access to files and folders in the working directory.

Data files that you package with your app (when you compile the app) are located in the assets folder in the file system. Your app has read-only access to this folder, which means that you can read data from files in this location, but you can't save new data in these files. When you create new data files dynamically while your app is running, they are stored in the data folder. Your app has full read-write access to this folder.

The working directory

The working directory (also known as the current directory or the sandbox) is the root directory for your application. It contains all the files installed with your application, provides a location for you to store additional content, and provides access to a number of shared folders accessible to all applications. Applications cannot create new directories or files at the root of the working directory, but they can in its subfolders. The following illustrates the working directory:

The BlackBerry 10 file system for an app

Apps can't create new directories in their working directory; they can access only the folders listed below. To access shared folders, the access_shared permission must be specified in the The bar-descriptor.xml file.

All path references in your application are relative to the root of the working folder. You should familiarize yourself with the following folders:

Folder Contains Access
Sandboxes/<app name>/app Files that were installed with your application. These files were packaged with your BAR file. read-only
Sandboxes/<app name>/app/native The application's binaries and resource files. read-only
Sandboxes/<app name>/app/data The app's private data. The app has full access to read and write files in this folder. You can use the $HOME environment variable to easily refer to this folder. read-write
Sandboxes/<app name>/db Files and database used by the app. read-only
Sandboxes/<app name>/tmp The app's temporary working files. Your app should remove these files regularly. The BlackBerry 10 Native SDK might remove these files any time that the app isn't running. read-write
Sandbox/<app name>/logs Logs files for an app. The app's stderr and stdout are forwarded to this directory. read-write
Sandbox/<app name>/shared Subfolders that contain shared data grouped by type. read-only
Sandbox/<app name>/shared/books eBook files that can be shared among apps. read-write
Sandbox/<app name>/shared/camera The camera roll that can be shared among apps. The camera roll contains recordings or images taken by an app with the camera. read-write
Sandbox/<app name>/shared/documents Documents that can be shared among apps. read-write
Sandbox/<app name>/shared/downloads Browser downloads. read-write
Sandbox/<app name>/shared/misc Miscellaneous data that can be shared among apps. read-write
Sandbox/<app name>/shared/music Music files that can be shared among apps. read-write
Sandbox/<app name>/shared/photos Photos that can be shared among apps. read-write
Sandbox/<app name>/shared/print Printed files that can be shared among apps. read-write
Sandbox/<app name>/shared/protected_media Contains the wallpapers that are provided with the device. Apps do not have access to the contents of this folder. none
Sandbox/<app name>/shared/videos Videos that can be shared among apps. read-write
Sandbox/<app name>/shared/voice Audio recordings that can be shared among apps. read-write
Sandbox/<app name>/sharewith Files that the application can share with other applications on the device. The files are shared using the App Integration (or Invocation) framework. read-write
Sandbox/<app name>/tmp The app's temporary working files. Your app should remove these files regularly. The BlackBerry 10 Native SDK might remove these files any time that the app isn't running. read-write

Navigating the file system

If you need to do any work in the file system, you should make yourself familiar with the Target File System Navigator view in the IDE. This view provides a clear look at the device file system and the application sandbox. It's useful for visualizing the directory structure, debugging your app, and getting to know how the file system is organized for your app.

To open the Target File System Navigator in the IDE, click Window > Show View > Target File System Navigator. By default, it should open in the bottom pane, beside the Console tab. Screen showing the Target File System Navigator and the contents of an app's working directory.

Within this view, you can explore the target and the working directories for the applications you've loaded.

The assets directory

Any assets that you have in your application (for example, images, sounds, and so on) must be kept in the assets folder in your project. In the file system, content in the assets folder for an application can be found in the app/native/assets directory. Since they're packaged with the application, assets are considered to be always available and immediately ready to be displayed, unlike other types of content that might be generated by the application or retrieved from a remote location.

The shared directory

The shared folder contains a set of subfolders that contain shared data grouped by type.

An application has only read access in this directory, but it can read and write to subfolders if the correct permission is applied.

To give your application write access to the shared subfolders, you must set the Shared Files permission (access_shared) in your bar-descriptor.xml file. For more information, see App permissions.

Screen showing the Shared Files check box.

For example, if you're creating a picture viewer application, you might want to be able to access the files in the shared/camera directory.

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus