0
votes

I am creating a file using phoneGap file writer. The files are getting created under the SD card for android. However, with the same code on iOS the files are getting created under the application sandbox. Please suggest if there is a way to create files under the android sandbox using phonegap filewriter api.

I am using code similar to below from phonegap examples.

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'
}
1

1 Answers

2
votes

When you call getFile you just need to pass the path to the application sandbox. For instance "/data/data/com.my.app/readme.txt" and you will be able to write to the sandbox.

We are talking about making this easier in a future release.