I am developing an application for Android using Cordova. I am already familiar with FileTransfer and I already know how to download a file. Problem is that when I am downloading a large file (20 MB) then this download tooks a while without notifying user that something is actually happening.
All I managed is download of file into sd card via:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
and then show dialog to user that file was downloading and where (s)he can find it. But I want let user know about progress. Or is it possible to somehow handle this file transfer in background so user may see a downloading icon in Android's top bar just like when downloading file via default browser?
Thank you very much for any help.
Code:
document.addEventListener('deviceready', function() {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, function(){
console.log("error getting LocalFileSystem");
});
}, false);
function gotFS(fileSystem) {
// save the file system for later access
window.rootFS = fileSystem.root;
}
fileTransfer.download(
http://somewhere.com/bigfile.zip,
window.rootFS,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
},
);
Raymond Camden wrote a nice article about this. You can use bootstrap in order to show a progressbar when using the progress-function of PhoneGap in order to let a progress bar grow:
fileTransfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
} else {
loadingStatus.increment();
}
};
Read here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With