【问题标题】:android phonegap file creation under the application sandbox应用程序沙箱下的android phonegap 文件创建
【发布时间】:2012-12-11 15:43:02
【问题描述】:

我正在使用 phoneGap 文件编写器创建一个文件。这些文件是在 Android 的 SD 卡下创建的。 但是,在 iOS 上使用相同的代码,文件是在应用程序沙箱下创建的。 请建议是否有一种方法可以使用phonegap filewriter api在android沙箱下创建文件。

我正在使用类似于以下 phonegap 示例的代码。

http://docs.phonegap.com/en/1.0.0/phonegap_file_file.md.html#FileWriter

document.addEventListener("deviceready", onDeviceReady, false);

// PhoneGap is ready
//
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    fileSystem.root.getFile("readme.txt", {create: true}, gotFileEntry, fail); 
}

function gotFileEntry(fileEntry) {
    fileEntry.createWriter(gotFileWriter, fail);
}

function gotFileWriter(writer) {
    writer.onwrite = function(evt) {
        console.log("write success");
    };
    writer.write("some sample text");
    // contents of file now 'some sample text'
    writer.truncate(11);
    // contents of file now 'some sample'
    writer.seek(4);
    // contents of file still 'some sample' but file pointer is after the 'e' in 'some'
    writer.write(" different text");
    // contents of file now 'some different text'
}

【问题讨论】:

    标签: cordova


    【解决方案1】:

    当您调用 getFile 时,您只需将路径传递给应用程序沙箱。例如“/data/data/com.my.app/readme.txt”,您将能够写入沙箱。

    我们正在讨论在未来的版本中简化此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-05
      相关资源
      最近更新 更多