0.0.3 • Published 3 years ago

cordova-plugin-background-filetransfer v0.0.3

Weekly downloads
-
License
Apache 2.0
Repository
github
Last release
3 years ago

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)

Set default values of the plugin.

ParamTypeDescription
optionsDownloadPreferencesDefault 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.

NameTypeDefaultDescription
allowNetworkMobileBooleantrueAllow download files from mobile network
allowNetworkWifiBooleantrueAllow download files from wifi network
allowedOverMeteredBooleantrueAllow download files in metered networks
allowedOverRoamingBooleantrueAllow download files when roaming is activated
defaultTitleString"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.

NameTypeDefaultDescription
urlStringRequiredAllow download files from mobile network.
filenameStringRequiredFilename, the name under which the file will be saved in the folder.
relativePathStringOptional valueName 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 valueHeaders for download if it are required.
descriptionStringfilenameThe description of the download, this value is displayed in the notification.

getFilesByStatus(downloadFileStatus)

Returns the list of files filtered by status. Posible values:

StatusValue
PENDING1
RUNNING2
PAUSED4
SUCCESSFUL8
FAILED16
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" />

Help liks:

Android Downloader manager