How do you download a file to Android's Downloads folder using Phonegap?

前端 未结 4 1383
天涯浪人
天涯浪人 2021-01-05 07:10

I have successfully downloaded a file to my Android phone using Phonegap\'s File API. I would like to download the file to the Downloads folder on my phone. For example, if

相关标签:
4条回答
  • 2021-01-05 07:27

    I have created a plugin which downloads file using download manager and shows progress bar along the way

    https://github.com/vasani-arpit/cordova-plugin-downloadmanager

    //after device is ready
    var fail = function (message) {    
       alert(message)
    }
    var success = function (data) {
       console.log("succes");
    }
    cordova.plugins.DownloadManager.download("Your URL to download", success, fail);
    

    I hope it helps.

    0 讨论(0)
  • 2021-01-05 07:27

    I had the same problem, but I solved it like this:

    //if IOS cordova.file.documentsDirectory
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (fileEntry) {
      var filepath = fileEntry.toURL() + filename;
      var fileTransfer = new FileTransfer();
      console.log('FilePath ' + filepath);
      fileTransfer.download(uri, filepath,
        function (fileEntry) {
          console.log("download complete: " + fileEntry.toURL());
        },
        function (error) {
          console.log("ErrorDownload: " + JSON.stringify(error));
        },
        true,
        {}
      );
    });
    
    0 讨论(0)
  • 2021-01-05 07:33

    You can send the file to the download folder by specifying it in the getFile method...

    getfile('download/myfile.jpg' ...)
    

    This doesn't trigger the DownloadManager which notifies you when a file has been downloaded. I am still trying to find a solution for having access to the DownloadManager class through phonegap. I have asked this question here How do you download a file to Android's Downloads folder using Phonegap?

    0 讨论(0)
  • 2021-01-05 07:40

    Use this plugin: https://github.com/sgrebnov/cordova-plugin-background-download. I use it in my Cordova app and it works fine.

    0 讨论(0)
提交回复
热议问题