【问题标题】:Apache cordova - unable to write to file in androidApache cordova - 无法在android中写入文件
【发布时间】:2013-09-29 18:58:57
【问题描述】:

我正在尝试在 javascript 中使用 cordova 的 api 在 PERSISTENT(SD 卡)存储中创建一个文件。我能够创建文件,但无法向其中写入数据(读取时数据为空)。下面是我的JS代码:

$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, false);
});

function onDeviceReady() {
    writeTestList();
}

function writeTestList() {
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystemForWrite, function() { showMsg('Unable to access file system for write'); });
  }

function gotFileSystemForWrite(fileSystem) {
    fileSystem.root.getFile('testList.txt', {create: true, exclusive: false}, gotFileEntryForWrite, function() { showMsg('Unable to access file for write'); });
}

function gotFileEntryForWrite(fileEntry) {
   fileEntry.createWriter(gotFileWriter, function() { showMsg('Unable to create test list'); });
}

function gotFileWriter(writer) {
    writer.onwrite = function(evt) {
      // show a message
      alert('created the test lists');
      readSavedContent();
   };
   writer.onerror = function(evt) {
     alert(JSON.stringify(evt));
   };
   writer.write("raj");
   alert(writer.length);
}

控件总是进入编写器的 onerror 并在警告事件 obj 时,我看到一个类型:“错误”,错误:“JSON 错误”。我完全不明白这一点。我正在写入一个 txt 文件,但收到 json 错误。我已经在 android manifest 中添加了写权限。另外,我在 config.xml 首选项中启用了cordova 的存储插件。各位,请帮我解决这个问题..!!

【问题讨论】:

  • 你能说一下如何让你的代码工作吗?我收到一个错误:未定义 requestFileSystem

标签: javascript android apache cordova cordova-3


【解决方案1】:

无法在 cordova 3.0 中解决此问题。移至cordova 2.9,一切正常。

【讨论】:

    猜你喜欢
    • 2017-04-08
    • 1970-01-01
    • 2016-07-08
    • 1970-01-01
    • 2014-03-30
    • 2018-11-11
    • 1970-01-01
    • 2011-09-16
    • 2015-12-07
    相关资源
    最近更新 更多