Skip to content Skip to sidebar Skip to footer

Cordova Resolvelocalfilesystemurl Callbacks Not Fired

I've been trying to run the following code but the callbacks [ok() and ko()] are not called. Using Worklight 6.2 (Cordova 3.4). function wlCommonInit() { window.requestFileSyst

Solution 1:

The code snippet in the question will not work in Android due to a Cordova defect: https://issues.apache.org/jira/browse/CB-7273.

To progress further, it would help to understand what are your plans for the file itself.

  • Do you simply want the path to the file
  • Or do you want to alter the contents of the file?
  • Or?

You can read more about file system operations in Cordova in this question/answer: Where does LocalFileSystem.PERSISTENT point to?

Solution 2:

I managed to access local fiiles in Worklight running an Android environment using a XMLHttpRequest:

//Works only on AndroidfunctionprendiCaricaRisorsaWorklight(percorsoPiuNomeFile) {

    var xmlhttp = newXMLHttpRequest();
    var risposta = "";
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4
                && (xmlhttp.status == 200 || xmlhttp.status == 0)) {
            risposta = xmlhttp.responseText; 
            alert(risposta); 
        }
    }
    xmlhttp.open("GET", "file:///android_asset/www/default/"
            + percorsoPiuNomeFile, true);
    xmlhttp.send(null);
}

Usage example:

prendiCaricaRisorsaWorklight("css/cssInterno.css");
prendiCaricaRisorsaWorklight("js/jsInterno.js");

This shows on Android an alert with the file content.

Post a Comment for "Cordova Resolvelocalfilesystemurl Callbacks Not Fired"