1#

使用phonegap插件
Downloader.rar (, 下载次数:354)


js文件做相应修改:
  1. function Downloader() {}



  2. Downloader.prototype.downloadFile = function(fileUrl, params, win, fail) {
  3.     //Make params hash optional.
  4.     if (!fail) win = params;
  5.     cordova.exec(win, fail, "Downloader", "downloadFile", [fileUrl, params]);
  6. };

  7. /*PhoneGap.addConstructor(function() {
  8.     PhoneGap.addPlugin("downloader", new Downloader());
  9.     PluginManager.addService("Downloader", "com.cfxixi.dubaotianxia.Downloader");
  10. });*/


  11. if(!window.plugins) {
  12.     window.plugins = {};
  13. }
  14. if (!window.plugins.downloader) {
  15.     window.plugins.downloader = new Downloader();
  16. }
复制代码
调用方式:
  1. var openWin=1;
  2.                             window.plugins.downloader.downloadFile(weiboImgUrl, {overwrite: true},
  3.                                       function(res) {
  4.                                         
  5.                                         if(openWin==1){
  6.                                             $.alertMasker("下载成功,在您的"+res.dir+"文件路径下");
  7.                                             openWin=0;
  8.                                         }
  9.                                         else
  10.                                         {
  11.                                             return false;
  12.                                         }
  13.                                         
  14.                                     }, function(error) {
  15.                                         $.alertMasker("该图片不能被下载");
  16.                                     }
  17.                                 );
复制代码
如此便可在0/Download文件夹下找到图片