Skip to content Skip to sidebar Skip to footer

Cordova 3.x (phonegap) - Write On /data/data Generates Encodingexception

I am trying to write a file on my application memory using the following code taken from here: writeOnFileSystem : function() { console.log('writeOnFileSystem resolveLocalF

Solution 1:

Edit: while this answer still holds, there are quite a few changes to the Cordova File API

Anyway,

When you call requestFileSystem it returns a FileSystem object which has a root property which is a DirectoryEntry.

When you call resolveLocalFileSystemURI it returns a DirectoryEntry or FileEntry.

So in your case you need to do:

window.resolveLocalFileSystemURI("file:///data/data/{package_name}", onSuccess, onError); 

functiononSuccess(entry) { 
    entry.getDirectory("example", {create: true, exclusive: false},onGetDirectorySuccess, onGetDirectoryFail); 
}
functiononError(error){
console.log(error);
}

the method resolveLocalFileSystemURI will give you access to the /data/data folder, then you go from there.

The problem with window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); is that on Android it will give you the SD card path if there is an SD card mounted on the device, otherwise it will give you the path to the internal storage (not even sure if data/data/{package_name} or somewhere else). If you ask me, this is one of the most stupid design choices of all times

Post a Comment for "Cordova 3.x (phonegap) - Write On /data/data Generates Encodingexception"