Search code examples
androidhtmlwebkitcordova-3

requestFileSystem does nothing in Android. Cordova 3.4


I have an app which was working fine up until this week, and I've no idea what has suddenly changed.

Consider the following code. The first "console.log" outputs correctly, but NOT ONE of the others outputs anything at all.

console.log('requesting file system');
try { 
  requestFileSystem(1, 1024*1024, function(fs) { 
    console.log('file system received. requesting root directory');
    fs.root.getDirectory( options.name, {create:true}, function( directory ) { 
      console.log('root directory received');
      filesystems[options.name] = directory;
      console.log('calling callback');
      if ( callback ) me.fn( me.name, callback ).call( me, me );
      console.log('callback called');
    }, function(e) { 
      console.log('error handler 1');
      console.log(e);
    });
  }, function(e) { 
    console.log('error handler 2');
    console.log(e);
  });
}
catch(e) { 
  console.log('error handler 3');
  console.log(e);
}

Any ideas what to look for?


Solution

  • This issue lot of them are facing, stems from a bug in cordova nativetoJSbridge. It has been marked fixed in 3.6.0, but never worked in that version. Couple of versions above the specific version works.

    Steps to fix it in your existing project if you are using eclipse.

    1. Install latest cordova using npm and create a new project using CLI.
    2. Add the file api to your new project using cordova plugin add command.
    3. Once the plugin is added to your project, copy the latest java sources of cordova as well as your file api to your old project.
    4. Also, copy the file api plugin javascript sources and diff and merge cordova.js.
    5. Now compiling your old project should fix window.requestFileSystem issue.

    If you are using CLI, even better. create a new project from CLI and copy your old project sources to new project and add the plugins using CLI or update your project using CLI.

    As a side note, this bug had been around for a while, where the problem seems to be in NativeToJsMessageQueue

    https://issues.apache.org/jira/browse/CB-6761

    Though from the bug it reads to be unresolved, it is fixed in latest version above 3.6.x