1

I have successfully downloaded a file using the phonegap download method. I am downloading the file to local storage in the Download folder on my android phone. I would like to have some kind of notification from the Download Manager that a file has been downloaded and then click on the download to view. This is what the phonegap download method lacks.

Does phonegap have access to the Android DownloadManager class?

squistbe
  • 305
  • 1
  • 3
  • 18
  • You would need to write a plugin. http://docs.phonegap.com/en/2.0.0/guide_plugin-development_index.md.html#Plugin%20Development%20Guide – Simon MacDonald Sep 25 '12 at 23:00

3 Answers3

0

You definitely need a plugin to access native code of android from phonegap.

Have a look at this site: https://github.com/phonegap/phonegap-plugins/tree/master/Android

It is full with plugins. One of them is called "downloader". Maybe that is what you are looking for.

SunnySonic
  • 1,318
  • 11
  • 37
0

The android downloader plugin works great. However if you are running on cordova 2.0 you will need to modify the code for adding a constructor. The current code is:

...

PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin("downloader", new Downloader());
    PluginManager.addService("Downloader", "com.phonegap.plugins.downloader.Downloader");
});

Since addPlugin no longer works on cordova 2.0 you will need to remove the addConstructor method and replace it with:

window.downloader = new Downloader();

And on the exec method should look like this:

cordova.exec(win, fail, "Downloader", "downloadFile", [fileUrl, params]);

Instead of using the Phonegap object. After I did all this, the plugin worked. The entire js should look like this:

function Downloader() {}

Downloader.prototype.downloadFile = function(fileUrl, params, win, fail) {

    //Make params hash optional.
    if (!fail) win = params;
cordova.exec(win, fail, "Downloader", "downloadFile", [fileUrl, params]);
};

window.downloader = new Downloader();
squistbe
  • 305
  • 1
  • 3
  • 18
0

use this plugin to access android DownloadManager

https://github.com/sgrebnov/cordova-plugin-background-download

i use it in my cordova app and it work fine.

maybe need some customization in java code to work perfect.