0

我正在使用 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'
}
4

1 回答 1

2

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

我们正在讨论在未来的版本中使这更容易。

于 2012-12-11T18:43:00.983 回答