Search code examples
androidcordovacordova-3cordova-plugins

cordova 3 and fullPath


In previous versions of cordova/phonegap the URL returned by fullPath and toURL() on a file or directory returned (in Android) "file:///mnt/sdcard".

window.requestFileSystem(
    LocalFileSystem.PERSISTENT,
    0,
    function(fs){
        console.log(fs.root.fullPath);
        console.log(fs.root.toURL());
    },
    function(error){
        console.error('Failed to get file system:' + error);
    }
);

The above code using cordova 3.3.1-0.4.2 is returning:

02-20 15:56:56.746 I/Web Console(27239): / at file:///android_asset/www/js/ui.js:64
02-20 15:56:56.746 I/Web Console(27239): cdvfile://localhost/persistent/ at file:///android_asset/www/js/ui.js:65

This is fine for using cordova based functionality but if I want to pass a URL to a third party library, the URL is meaningless. (My example is I have a GPX file stored locally and I need to pass the location to an openlayers layer)


Solution

  • The new cdvfile protocol does not work in android 2, for this reason the method toNativeURL() has been added to 1.0.1 of the org.apache.cordova.file plugin, see https://issues.apache.org/jira/browse/CB-6106.