I've written a Cordova plugin to download a file and save it in the data folder. Everything is working fine except for the return value. I would like to display a progress bar and need to get the current progress. Here's 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);
}
What happens is that the progress will only be output after the file has been downloaded. If I set the PluginResult.Status to NO_RESULT, it won't output anything at all.