BulkDownloader is used for multiple downloading process easy. It provides progress listener for each files and for whole file. It guarantees completion of download files as it runs on work manager
You want to download 100's of images in background You want progress of each file being downloaded and total images downloaded.
Copy and paste this dependency in module gradle
implementation 'balakrishnan.me.bulkdownloader:bulkdownloader:0.0.5'
Implement
ImageDownloaderHelper.DownloadStatus
in the activity or fragment that you want to track your record or you can follow below given method in the Activity or Fragment
If you wanted to download a list of images then call BulkDownloader as follows
new ImageDownloaderHelper().setUrls(ArrayList of urls))
.setDownloadStatus(getCallback())
.setCollectionId(uniqueId)
.create();
getCallback() method is as follows
public ImageDownloaderHelper.DownloadStatus getCallback() {
return new ImageDownloaderHelper.DownloadStatus() {
@Override
public void DownloadedItems(int totalurls, int downloadPercentage, int successPercent, int failurePercent) {
//You can get Total Image Downloaded progress here
}
@Override
public void CurrentDownloadPercentage(LinkedHashMap<String, ProgressModel> trackRecord) {
//You can get Induvidual Image Downloaded progress here
}
};
}
Let's say if you want to download all images in a any response
Example:
[
{"id":"1","createdAt":"2018-10-22T23:34:56.999Z","name":"Cornelius Fadel","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/areus/128.jpg"},
{"id":"2","createdAt":"2018-10-22T22:59:42.972Z","name":"Freeman Balistreri","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/matbeedotcom/128.jpg"},
{"id":"3","createdAt":"2018-10-22T19:08:53.211Z","name":"Angus Johnson","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/cdharrison/128.jpg"},
{"id":"4","createdAt":"2018-10-23T01:38:08.226Z","name":"Ashleigh Baumbach","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/michaelmartinho/128.jpg"},
{"id":"5","createdAt":"2018-10-23T14:08:41.273Z","name":"Sasha Bernhard","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/kikillo/128.jpg"},
.
.
.
{"id":"24","createdAt":"2018-10-23T15:12:14.040Z","name":"Mr. Barton Hickle","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/markolschesky/128.jpg"}
]
You need to add following code in your activity / Fragment
new ImageDownloaderHelper().setDownloadStatus(getCallback())
.setUrl(`some_url`)
.setCollectionId(uniqueId)
.createImageDownloadWorkURl();
getCallback() method is as follows
public ImageDownloaderHelper.DownloadStatus getCallback() {
return new ImageDownloaderHelper.DownloadStatus() {
@Override
public void DownloadedItems(int totalurls, int downloadPercentage, int successPercent, int failurePercent) {
//You can get Total Image Downloaded progress here
}
@Override
public void CurrentDownloadPercentage(LinkedHashMap<String, ProgressModel> trackRecord) {
//You can get Induvidual Image Downloaded progress here
}
};
}
Receiving download status if app is not running
You will get information in the receiver of download only if app is not running