Search code examples
javascriptblackberrycordovablackberry-webworks

Phonegap/Cordova getDirectory fails on BlackBerry


I have an app that works correctly on Android and iOS, but currently fails on BlackBerry (OS 6.0+). The app used to work on all 3 flavors, but since converting the app to download updates dynamically (rather than re-publishing the app each time there's a minor change to some Javascript), the app fails to get past the getDirectory function. I am using Cordova 1.8.1.

Here is the beginning part of my JavaScript code that executes when the device is ready:

function onDeviceReady(){
    // get the filesystem setup and run the pre-loader (follow the callback road)
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail_FS);
}

function gotFS(fileSystem) {
   fileSystem.root.getDirectory("data", {create: true}, gotDir, fail_GD);   
}

function gotDir(dir) {
    console.log("got dir");
    DATADIR = dir;
    // code for downloading/updating files goes here
    // left out for brevity and lack of relevance at this point
}

function fail_FS(error){
    fail(error,'requestFileSystem');
}

function fail_GD(error){
    fail(error,'getDirectory');
}

function fail(error,call){
    console.log("ERROR: "+call);
    console.log(JSON.stringify(error));
}

I get an Error Code of 1 from the getDirectory call (GotFS function). I have added extra comments to test. Here is what I know:

fileSystem = 'persistent' fileSystem.root.name = "" fileSystem.root.fullPath = 'file:///store'

I've checked the documentation on Cordova here and here and here is what I have in my config.xml

<feature id="blackberry.system" required="true" version="1.0.0.0" />
<feature id="org.apache.cordova" required="true" version="1.0.0" />
<feature id="blackberry.find" required="true" version="1.0.0.0" />
<feature id="blackberry.identity" required="true" version="1.0.0.0" />
<feature id="blackberry.pim.Address" required="true" version="1.0.0.0" />
<feature id="blackberry.pim.Contact" required="true" version="1.0.0.0" />
<feature id="blackberry.io.file" required="true" version="1.0.0.0" />
<feature id="blackberry.utils" required="true" version="1.0.0.0" />
<feature id="blackberry.io.dir" required="true" version="1.0.0.0" />
<feature id="blackberry.app" required="true" version="1.0.0.0" />
<feature id="blackberry.app.event" required="true" version="1.0.0.0" />
<feature id="blackberry.system.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/>
<feature id="blackberry.media.camera" />
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.BrowserArguments" />
<feature id="blackberry.identity" />
<feature id="blackberry.ui.dialog" />
<feature id="blackberry.system" />

<access subdomains="true" uri="file:///store" />
<access subdomains="true" uri="file:///store/data" />
<access subdomains="true" uri="file:///SDCard" />
<access subdomains="true" uri="*" />
<rim:permissions>
    <rim:permit>use_camera</rim:permit>
    <rim:permit>read_device_identifying_information</rim:permit>
    <rim:permit>access_shared</rim:permit>
    <rim:permit>read_geolocation</rim:permit>
</rim:permissions>

Among other info... And here is what's in my plugins.xml:

<plugins>
  <plugin name="App"            value="org.apache.cordova.app.App"/>
  <plugin name="Device"         value="org.apache.cordova.device.Device"/>
  <plugin name="Camera"         value="org.apache.cordova.camera.Camera"/>
  <plugin name="NetworkStatus"  value="org.apache.cordova.network.Network"/>
  <plugin name="Notification"   value="org.apache.cordova.notification.Notification"/>
  <plugin name="Accelerometer"  value="org.apache.cordova.accelerometer.Accelerometer"/>
  <plugin name="Geolocation"    value="org.apache.cordova.geolocation.Geolocation"/>
  <plugin name="File"           value="org.apache.cordova.file.FileManager"/>
  <plugin name="FileTransfer"   value="org.apache.cordova.http.FileTransfer"/>
  <plugin name="Contacts"       value="org.apache.cordova.pim.Contact"/>
  <plugin name="Capture"        value="org.apache.cordova.capture.MediaCapture"/>
  <plugin name="Battery"        value="org.apache.cordova.battery.Battery"/>
  <plugin name="Media"          value="org.apache.cordova.media.Media"/>
  <plugin name="ChildBrowser"   value="org.apache.cordova.plugins.childbrowser.ChildBrowser"/>
</plugins>

I suspect it's just a matter of something simple (like I'm doing something wrong with the access permissions in the xml), but after trying various different things and searching all over the internet, I'm stumped...

Any help would be appreciated.


Solution

  • Your code looks correct to me.

    If you have the BlackBerry connected to USB and entered your device password when prompted at the "USB Drive" screen, you would have enabled 'mass media/storage mode'. This will lock the file system to the USB and prevent your app from accessing it. I would expect you would see an error when trying to call fileSystem.root.getDirectory.