I wrote a Cordova plugin to upload a file and save it in a data folder. Everything is working fine except for the return value. I would like to display a progress bar and get the current progress. Here is the relevant part from my code:
while ((readed = is.read(buffer)) > 0) { fos.write(buffer, 0, readed); totalReaded += readed; int newProgress = (int) (totalReaded*100/fileSize); if (newProgress != progress) { progress = newProgress; PluginResult res = new PluginResult(PluginResult.Status.OK, progress); res.setKeepCallback(true); callbackContext.sendPluginResult(res); } }
My JavaScript:
downloader.prototype.writeFile = function (downloaderSuccess, downloaderFailure, options) { cordova.exec(downloaderSuccess, downloaderFailure, "downloader", "writeFile", options); }; function downloaderSuccess(progress) { WL.Logger.debug("Result: "+progress) } function downloaderFailure(error) { WL.Logger.error("Error: "+error); }
It happens that the progress will be displayed only after downloading the file. If I set PluginResult.Status to NO_RESULT, it does not output anything.
RenΓ© source share