项目作者: vasani-arpit

项目描述 :
A Cordova plugin to download file in system's default download manager
高级语言: Java
项目地址: git://github.com/vasani-arpit/cordova-plugin-downloadmanager.git


cordova-plugin-downloadmanager

A Cordova plugin to download file in system’s default download manager

Supported Platforms

  • Android (SDK >= 11)

    Installation

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

    How to Use

  1. //after device is ready
  2. var fail = function (message) {
  3. alert(message)
  4. }
  5. var success = function (data) {
  6. console.log("succes");
  7. }
  8. cordova.plugins.DownloadManager.download("Your URL to download", "Your file name","Your Description" ,success, fail);
  1. var options = {
  2. setDestinationInExternalPublicDir: true // set true if you want to use public dir instead of files dir
  3. }
  4. cordova.plugins.DownloadManager.download("Your URL to download", "Your file name","Your Description" ,success, fail, options)

To add an already downloaded file to the Downloads database.

  1. // Full absolute path the the already downloaded file. It should be in file:///storage/emulated/0/Download/ or subfolder.
  2. const filepath_sanitized = filepath.replace("file://", ""); // Note: Don't include any file:// prefix in the path.
  3. /**
  4. * Method that calls the addCompletedDownload method on the DownloadManager object
  5. * @param {string} title Must match the filename which was written.
  6. * @param {string} description doesn't seem used?
  7. * @param {string} mimeType i.e. "text/plain"
  8. * @param {string} path Absolute file path. Note: Don't include any file:// prefix in the path.
  9. * @param {number} length size of the downloaded file
  10. * @param {function(string)} success callback
  11. * @param {function(string)} error callback
  12. */
  13. cordova.plugins.DownloadManager.addCompletedDownload(filename, "Your Description", 'text/*', filepath_sanitized, length,
  14. (result) => {
  15. console.info(result);
  16. },
  17. (err) => {
  18. console.error(err);
  19. })

Result

screenshot

If this plugin helps your project then don’t forget to ⭐ star the repo.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request