IO

The IO Object contains properties that can be used to navigate the filesystem.

Since: BlackBerry WebWorks 2.0

This object allows you to access folders on your device such as the home folder, SD card, shared folder, data lock startup folder, and data lock operational folder. It also allows you to control whether or not the filesystem is sandboxed.

Installation:

To use this API in your project, add the io plugin:

webworks plugin add com.blackberry.io

Example:

<script type="text/javascript">

function readFile() {
   // un-sandbox file system to access shared folder
   blackberry.io.sandbox = false;

   window.requestFileSystem  = window.requestFileSystem || 
      window.webkitRequestFileSystem;

   window.requestFileSystem(window.TEMPORARY, 1024 * 1024,
      function (fs) {
          // In order to access the shared folder, config.xml
          // file must declare the "access_shared" permission.
          // Reference the file by absolute path since file 
          // system is un-sandboxed.
          fs.root.getFile(blackberry.io.sharedFolder 
             + '/Documents/log.txt', {create: true},
             function (fileEntry) {
                fileEntry.file(function (file) {
                   var reader = new FileReader();

                   reader.onloadend = function (e) {
                      var txtArea = 
                          document.createElement('textarea');
                      txtArea.value = this.result;
                      document.body.appendChild(txtArea);
                   };

                   reader.readAsText(file);
                }, errorHandler);
             }, errorHandler);
      });
}

function errorHandler(e) {
    var msg = '';

    switch (e.code) {
    case FileError.QUOTA_EXCEEDED_ERR:
        msg = 'QUOTA_EXCEEDED_ERR';
        break;
    case FileError.NOT_FOUND_ERR:
        msg = 'NOT_FOUND_ERR';
        break;
    case FileError.SECURITY_ERR:
         msg = 'SECURITY_ERR';
         break;
    case FileError.INVALID_MODIFICATION_ERR:
         msg = 'INVALID_MODIFICATION_ERR';
         break;
    case FileError.INVALID_STATE_ERR:
         msg = 'INVALID_STATE_ERR';
         break;
    default:
         msg = 'Unknown Error';
        break;
    };

    console.log('Error: ' + msg);
}

</script>
Properties:
String dataLockOperationalHome (new in 2.2)
String dataLockStartupHome (new in 2.2)
String home
Boolean sandbox
String SDCard
String sharedFolder

dataLockOperationalHome

The full file path for the data lock operational folder. This folder is available to apps that have the "access_operational_data_domain" permission, except when the dataLockState is "startupLocked".

To access the data lock operational folder, the config.xml file must declare the "access_operational_data_domain" permission. For more information about data lock folders and advanced data at rest protection, see Creating apps that are data lock aware.

Synopsis:

read-only
String blackberry.io.dataLockOperationalHome

dataLockStartupHome

The full file path for the data lock startup folder. This folder is available to apps that have the "access_startup_data_domain" permission.

To access the data lock startup folder, the config.xml file must declare the "access_startup_data_domain" permission. For more information about data lock folders and advanced data at rest protection, see Creating apps that are data lock aware.

Synopsis:

read-only
String blackberry.io.dataLockStartupHome

home

The full file path for the application data folder.

Synopsis:

read-only
String blackberry.io.home

sandbox

Whether the file system is sandboxed. It is set to true by default.

When sandbox is set to false, you must use absolute path to reference a file or directory. You can use dataLockOperationalHome, dataLockStartupHome, home, SDCard, or sharedFolder to construct file paths.

Synopsis:

Boolean blackberr.io.sandbox = true

SDCard

The full file path for the SD card folder.

To access the SD card, the config.xml file must declare the "access_shared" permission.

Synopsis:

read-only
String blackberry.io.SDCard

sharedFolder

The full file path for the shared folder.

To access the sharedFolder, the config.xml file must declare the "access_shared" permission.

Synopsis:

read-only
String blackberry.io.sharedFolder

Last modified: 2014-10-09



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

comments powered by Disqus