thatsjojo-cordova-plugin-downloadmanager
v0.0.6
Published
A plugin to start system's default download manager.
Downloads
12
Readme
cordova-plugin-downloadmanager
A Cordova plugin to download file in system's default download manager
Supported Platforms
- Android (SDK >= 11)
Installation
cordova plugin add https://github.com/ThatsJojo/cordova-plugin-downloadmanager
How to Use
//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", "Your file name","Your Description" ,success, fail);
var options = {
setDestinationInExternalPublicDir: true, // set true if you want to use public dir instead of files dir
useIncomingFileName: true, // set true if you want to use the fileName extracted from the url
openAfterDownload: true, // set true if you want to open the in other app after download
openInDefaultApp: true, // set true if you want to open the file in the default app after download (needs openAfterDownload = true)
}
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.
// Full absolute path the the already downloaded file. It should be in file:///storage/emulated/0/Download/ or subfolder.
const filepath_sanitized = filepath.replace("file://", ""); // Note: Don't include any file:// prefix in the path.
/**
* Method that calls the addCompletedDownload method on the DownloadManager object
* @param {string} title Must match the filename which was written.
* @param {string} description doesn't seem used?
* @param {string} mimeType i.e. "text/plain"
* @param {string} path Absolute file path. Note: Don't include any file:// prefix in the path.
* @param {number} length size of the downloaded file
* @param {function(string)} success callback
* @param {function(string)} error callback
*/
cordova.plugins.DownloadManager.addCompletedDownload(filename, "Your Description", 'text/*', filepath_sanitized, length,
(result) => {
console.info(result);
},
(err) => {
console.error(err);
})
Result
If this plugin helps your project then don't forget to ⭐ star the repo.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request