javascript - File Errors in Android Cordova -
i thought i'd post may useful others, i've struggled error feedback while lodging files in android/cordova hybrid application. next blocks of code should create easier - pointers improvement welcome.
fail: function(error) { var logger = cordova.require("salesforce/util/logger"); switch(error.code) { case fileerror.not_found_err: logger.logtoconsole("file not found"); break; case fileerror.security_err: logger.logtoconsole("security error"); break; case fileerror.abort_err: logger.logtoconsole("abort error"); break; case fileerror.not_readable_err: logger.logtoconsole("not readable"); break; case fileerror.encoding_err: logger.logtoconsole("encoding error"); break; case fileerror.no_modification_allowed_err: logger.logtoconsole("no modification allowed"); break; case fileerror.invalid_state_err: logger.logtoconsole("invalid state"); break; case fileerror.syntax_err: logger.logtoconsole("syntax error"); break; case fileerror.invalid_modification_err: logger.logtoconsole("invalid modification error"); break; case fileerror.quota_exceeded_err: logger.logtoconsole("quota exceeded"); break; case fileerror.type_mismatch_err: logger.logtoconsole("type mismatch error"); break; case fileerror.path_exists_err: logger.logtoconsole("path exists error"); break; } logger.logtoconsole("error code:: " + error.code); }
here file save routine causing issues (turned out needed create: true flag). hope it's helpful.
savelocal: function (file, data, sync) { //accept json of inspection object cordova.require("salesforce/util/logger").logtoconsole("writing " + file); //write info requested file window.requestfilesystem(localfilesystem.persistent, 0, function(filesystem) { cordova.require("salesforce/util/logger").logtoconsole("writing " + file); filesystem.root.getfile(file, {create: true}, function(fileentry) { cordova.require("salesforce/util/logger").logtoconsole("create writer"); fileentry.createwriter(function (writer) { writer.write(json.stringify(data)); //trigger send info salesforce if (sync) {sync();} //send event if registered if (onsaveend) {onsaveend(data);} }, anytime.fail); }, anytime.fail); }, anytime.fail); }
javascript android cordova
No comments:
Post a Comment