Skip to content

Cordova plugin to copy a file to the Downloads directory and notify about it to the Download Manager (Android only)

License

Notifications You must be signed in to change notification settings

tonib/cordova-plugin-copytodownload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Copy to Download folder

Cordova plugin for Android only (API >= 12). It allows to copy a local file to the Download folder and notify the Download Manager app that the file was "downloaded".

Additionally you can show a notification with that "download"

Requires WRITE_EXTERNAL_STORAGE and INTERNET permission. It can prompt the user for a permission to write the file.

Tested only with Cordova 6.1

Installation

cordova plugin add https://github.com/tonib/cordova-plugin-copytodownload.git [--save]

Refer to Cordova documentation for other ways to install (config.xml)

API

module.exports = window.CopyToDownload = CopyToDownload = {

    /**
     * Copy a file to the Download directory, and notify the DownloadManager of that file.
     * @param {string}  url     URL / path to the local file to copy to the Download directory.
     * @param {string}  title   the title that would appear for this file in Downloads App.
     * @param {string}  description the description that would appear for this file in Downloads App.
     * @param {boolean} isMediaScannerScannable true if the file is to be scanned by MediaScanner. Files scanned by MediaScanner appear in 
     *                                          the applications used to view media (for example, Gallery app).
     * @param {string}  mimeType    mimetype of the file.
     * @param {boolean} showNotification    true if a notification is to be sent, false otherwise
     * @param {function}    callbackSuccess Callback to call if the call was OK. A parameter will be passed with the id given by the Download Manager 
     *                                      to the download, as an String
     * @param {function}    callbackError   Callback to call if the call did fail. A parameter with the error will be passed
     */
    copyToDownload: function( url, title, description, isMediaScannerScannable, mimeType, showNotification , callbackSuccess, callbackError ) {
         /*...*/
    },

    /**
     * Copy a file to a destination directory, with native URLs
     * @param {string} srcFileUrl URL to to the local file to copy (copy source)
     * @param {string} dstDirectoryUrl URL to the local directory where to copy (copy destination)
     * @param {function} callbackSuccess Success callback. A parameter will be passed with the new copied file URL
     * @param {function} callbackError   Callback to call if the call did fail. A parameter with the error will be passed
     */
    copyNativePaths: function( srcFileUrl , dstDirectoryUrl , callbackSuccess, callbackError ) {
        /*...*/
    }
}

About

Cordova plugin to copy a file to the Downloads directory and notify about it to the Download Manager (Android only)

Resources

License

Stars

Watchers

Forks

Packages

No packages published