0

I am new to Phonegap and I am currently developing an android app using jquery mobile and Phonegap.

I googled a lot on how to use the downloader plugin and how to call it in your Html file which contains the link of the file you want to download with the downloader plugin but couldn't find any working example.

Can anyone here please provide me with a simple working demo of the PhoneGap downloader plugin so that I will get relevant information on how to use it. Or help me in implementing the plugin and calling it on the specific url.

Thanks in advance. :)

Sadegh
  • 865
  • 1
  • 23
  • 47

1 Answers1

0

I've used a downloader plugin quite a long time ago with phonegap 2.2 and it was quite easy to use.

Is this the plugin you are trying to use? or maybe this one?

The fist one seems to have been updated for the phonegap 2.7+ format so maybe usable in a phonegap 3 project, except that you won't be able to install using the CLI and will have to had the plugin manually in platform/android or you could write a plugin.xml yourself.

To use it, you just have to follow the instructions in the readme.md or read the original article in http://www.toforge.com/2011/02/phonegap-android-plugin-for-download-files-from-url-on-sd-card/

Again I haven't tried to use it in recent versions of phonegap and am not sure if the plugin should be updated to be compatible.

Edit: For each file you have to call:

window.plugins.downloader.downloadFile("http://server/file.txt", {overwrite: true}, 
      function(res) {
        //function called when the file is downloaded
        //the file content is in res
    }, function(error) {
        //function called in case of error
    }
);

if you need to download several files, you could download the next file in the function called in case of success.

QuickFix
  • 11,661
  • 2
  • 38
  • 50
  • Thanks for your reply. I already followed the tutorial you provided and configured the plugin successfully but I fail in calling the plugin in the HTML which contains the link to the Downloads I want to download with the Downloader Plugin. – user3199306 Jan 16 '14 at 05:39
  • What version of the plugin are you using (URL) and what version of phonegap are you using? The tutorial and one of the repossitories are good only for phonegap older than v2.7 – QuickFix Jan 16 '14 at 07:16
  • Sir, I used the same version as was suggested in the tutorial you provided. I did the configuration too and didn't faced any problem but I have no idea about calling the plugin to download a particular file. I wonder will it download every file or we have to specify the Url of the file we want to download.? – user3199306 Jan 17 '14 at 14:45
  • Thanks. Does it mean if I call the plugin once for a file (say file.txt) and now if I provide that link with a href tag. Will it start downloading through the downloader.? This gonna rectify my doubts. Thanks once again. – user3199306 Jan 17 '14 at 16:43
  • the downloader plugin allows you to receive the content of the file in a javascript object. In the function called in case of success you have to use javascript to do what ever you need with that file content. To be able to use the file as a href, you should first write the file using the phonegap file api. Also be aware that I don't think the downloader plugin will allow you to download something else than text files. – QuickFix Jan 17 '14 at 16:52
  • Thanks for the info and I think I now understood the way this plugins works and behaviour of it on different events. Thanks for your help. – user3199306 Jan 17 '14 at 16:59
  • I think that what you are looking for is more the FileTransfer.download function of phonegap. doc there : http://docs.phonegap.com/en/edge/cordova_file_file.md.html#File and a good example there : http://stackoverflow.com/questions/6417055/download-files-and-store-them-locally-with-phonegap-jquery-mobile-android-and-io – QuickFix Jan 17 '14 at 17:00