【问题标题】:Cordova resolveLocalFileSystemURL callbacks not firedCordova resolveLocalFileSystemURL 回调未触发
【发布时间】:2014-12-16 21:36:14
【问题描述】:

我一直在尝试运行以下代码,但未调用回调 [ok() 和 ko()]。
使用 Worklight 6.2 (Cordova 3.4)。

function wlCommonInit() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
            success, fail);

    window.resolveLocalFileSystemURL(cordova.file.applicationDirectory
            + "www/index.html", ok, ko);
}

function ko(e) {
    alert("NO");
}

function ok(fileEntry) {
    alert("OK");
}

另一方面,requestFileSystem 回调被定期调用。

【问题讨论】:

  • 你能用你正在使用的更完整的代码 sn-p 更新问题吗?

标签: android cordova ibm-mobilefirst


【解决方案1】:

由于 Cordova 缺陷,问题中的代码 sn-p 在 Android 中不起作用:https://issues.apache.org/jira/browse/CB-7273

为了进一步取得进展,了解您对文件本身的计划将有所帮助。

  • 你只是想要文件的路径
  • 还是要更改文件的内容?
  • 或者?

您可以在此问题/答案中阅读有关 Cordova 中文件系统操作的更多信息:Where does LocalFileSystem.PERSISTENT point to?

【讨论】:

    【解决方案2】:

    我设法使用XMLHttpRequest 访问运行Android 环境的Worklight 中的本地文件:

    //Works only on Android
    function prendiCaricaRisorsaWorklight(percorsoPiuNomeFile) {
    
        var xmlhttp = new XMLHttpRequest();
        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);
    }
    

    使用示例:

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

    这会在 Android 上显示带有文件内容的警报。

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      相关资源
      最近更新 更多