Where is the location using android File access with cordova/phonegap -
i started using phonegap android app development. trying write file using code (following phonegag example).
document.addeventlistener("deviceready", ondeviceready, false); // cordova ready // function ondeviceready() { window.requestfilesystem(localfilesystem.persistent, 0, gotfs, fail); } function writetext(file, text) { filename = file; texttowrite = text; window.requestfilesystem(localfilesystem.persistent, 0, gotfs, fail); } function gotfs(filesystem) { filesystem.root.getfile(filename, {create: true, exclusive: false}, gotfileentry, fail); } function gotfileentry(fileentry) { fileentry.createwriter(gotfilewriter, fail); } function gotfilewriter(writer) { writer.seek(writer.length); writer.write(texttowrite); console.log("output: " + texttowrite); } function fail(error) { console.log(error.code); }
in android emulator eclipse debugger, can see lines executed (log line printed out). no errors anywhere. however, not find file in system. should file go? can @ in windows?
here how call writer. writetext("test.txt", "ending ...");
where file test.txt? or, maybe got wrong?
many thanks!
i believe phonegap place file in /mnt/storage/sdcard0
on device.
for emulator can find doing -
- switch ddms perspective
- select emulator in devices list, sdcard want explore.
- open file explorer tab on right hand side.
- expand tree structure. mnt/sdcard/
i suggest putting callback function inside gotfilewriter
know when write has finished -
function gotfilewriter(writer) { writer.onwriteend = function(evt) { console.log('write has finished'); }; writer.seek(writer.length); writer.write(texttowrite); }
Comments
Post a Comment