Reputation: 315
I my app I use phonegap build to compile it for android. I need to create a persistent folder to store some audio files but I can't make it work... Here is my code :
in config.xml
<gap:plugin name="org.apache.cordova.file" version="0.2.4" />
And in my index.html :
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getDirectory("mynewfolder", {create: true}, gotDir);
console.log(fileSystem.root);
}
function gotDir(dirEntry) {
dirEntry.getFile("myfile.txt", {create: true, exclusive: true}, gotFile);
}
function gotFile(fileEntry) {
// Do something with fileEntry here
}
I have no explanation do you have some clues? The console give nothing.
Upvotes: 2
Views: 4544
Reputation: 1455
Well your code was fine but the problem was you missed error callback.... So your modified code will look like
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getDirectory("mynewfolder", {create: true}, gotDir,fail);
console.log(fileSystem.root);
}
function gotDir(dirEntry) {
dirEntry.getFile("myfile.txt", {create: true, exclusive: true}, gotFile,fail);
}
function gotFile(fileEntry) {
// Do something with fileEntry here
}
function fail(error) {
console.log(error.code);
}
Upvotes: 4