cordova-plugin-background-filetransfer
v0.0.3
Published
*Cordova plugin background file transfer* ========================================================= This plugin givess you the android DownloadManager methods for cordova. At the moment we only supports android projects, but we are planning implement the
Downloads
6
Maintainers
Readme
Cordova plugin background file transfer
This plugin givess you the android DownloadManager methods for cordova. At the moment we only supports android projects, but we are planning implement the features for iOS. In the future, the possibility of uploading files will be added too.
Instalation
cordova plugin add cordova-plugin-background-filetransfer
API Reference
- Download service
- .setDownloadPreferences(options) : Promise
- .getDownloadPreferences() : Promise
- DownloadPreferences : Object
- .addUrlToDownload(options) : Promise
- DownloadOptions : Object
- .getFilesByStatus() : Promise
- .getFileInfoById() : Promise
Download service
.setDownloadPreferences(options)
Set default values of the plugin.
| Param | Type | Description | | --- | --- | --- | | options | DownloadPreferences | Default download preferences |
cordova.plugins.BackgroundFileTransfer.setDownloadPreferences(downloadPreferences).then((result)=> {
console.log(result);
}, (err) => {
console.error(err);
});
.getDownloadPreferences()
Get default values of the plugin.
cordova.plugins.BackgroundFileTransfer.getDownloadPreferences().then((result)=> {
console.log(result);
}, (err) => {
console.error(err);
});
DownloadPreferences
Optional parameters to customize download settings.
| Name | Type | Default | Description | | --- | --- | --- | --- | | allowNetworkMobile | Boolean | true | Allow download files from mobile network | | allowNetworkWifi | Boolean | true | Allow download files from wifi network | | allowedOverMetered | Boolean | true | Allow download files in metered networks | | allowedOverRoaming | Boolean | true | Allow download files when roaming is activated | | defaultTitle | String | "DownloadService" | This is notification title |
addUrlToDownload(downloadOptions)
Add new url to enqueue download files. It returns the id of the file download.
cordova.plugins.BackgroundFileTransfer.addUrlToDownload(downloadOptions).then((result)=> {
console.log(result);
}, (err) => {
console.error(err);
});
DownloadOptions
The options that are required for add new download to enqueue.
| Name | Type | Default | Description | | --- | --- | --- | --- | | url | String | Required | Allow download files from mobile network. | | filename | String | Required | Filename, the name under which the file will be saved in the folder. | | relativePath | String | Optional value | Name of the folder in which the file is to be saved the file to be saved the file to be saved. | | headers | {"KEY": "VALUE"} | Optional value | Headers for download if it are required. | | description | String | filename | The description of the download, this value is displayed in the notification. |
getFilesByStatus(downloadFileStatus)
Returns the list of files filtered by status. Posible values:
| Status | Value | | --- | --- | | PENDING | 1 | | RUNNING | 2 | | PAUSED | 4 | | SUCCESSFUL | 8 | | FAILED | 16 |
cordova.plugins.BackgroundFileTransfer.getFilesByStatus(downloadFileStatus).then((result)=> {
console.log(result);
}, (err) => {
console.error(err);
});
getFileInfoById(fileId)
Returns the file list filtered by downloaded id.
cordova.plugins.BackgroundFileTransfer.getFileInfoById(fileId).then((result)=> {
console.log(result);
}, (err) => {
console.error(err);
});
Notes
Be sure that your AndroidManifest.xml contains this permission
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />