An extension of "PRDownloader" by "Mindorks" having a DownloaderQueue to control downloads properly
- EPRDownloader can be used to download any type of files like image, video, pdf, apk and etc.
- Supports pause and resume while downloading a file.
- Supports large file download.
- Simple interface to make download request.
- We can check if the status of downloading with the given download Id.
- EPRDownloader gives callbacks for everything like onProgress, onCancel, onStart, onError and etc while downloading a file. (Resetable anytime)
- Supports proper request canceling.
- Many requests can be made in parallel.
- All types of customization are possible.
- -> Has a Request Queue to handle download requests properly.
Add this in your build.gradle
implementation 'com.github.arefbhrn:EPRDownloader:1.0.1'
Do not forget to add internet permission in manifest if already not present
<uses-permission android:name="android.permission.INTERNET" />
Then initialize it in onCreate() Method of application class :
EPRDownloader.initialize(getApplicationContext());
Initializing it with some customization
// Enabling database for resume support even after the application is killed:
EPRDownloaderConfig config = EPRDownloaderConfig.newBuilder()
.setDatabaseEnabled(true)
.build();
EPRDownloader.initialize(getApplicationContext(), config);
// Setting timeout globally for the download network requests:
EPRDownloaderConfig config = EPRDownloaderConfig.newBuilder()
.setReadTimeout(30_000)
.setConnectTimeout(30_000)
.build();
EPRDownloader.initialize(getApplicationContext(), config);
DownloadRequest download = EPRDownloader.download(ur, folderName + "/", fileName).build()
.addOnStartOrResumeListener(new OnStartOrResumeListener() {
@Override
public void onStartOrResume() {
}
})
.addOnPauseListener(new OnPauseListener() {
@Override
public void onPause() {
}
})
.addOnCancelListener(new OnCancelListener() {
@Override
public void onCancel() {
}
})
.addOnProgressListener(new OnProgressListener() {
@Override
public void onProgress(Progress progress) {
}
})
.addOnDownloadListener(new OnDownloadListener() {
@Override
public void onDownloadComplete() {
}
@Override
public void onError(Error error) {
}
});
download.start();
EPRDownloader.pause(downloadId);
EPRDownloader.resume(downloadId);
// Cancel with the download id
EPRDownloader.cancel(downloadId);
// The tag can be set to any request and then can be used to cancel the request
EPRDownloader.cancel(TAG);
// Cancel all the requests
EPRDownloader.cancelAll();
int downloadId = Utils.getUniqueId(url, folderName + "/", fileName);
Or if download object is already defined:
int downloadId = download.getDownloadId();
Status status = EPRDownloader.getStatus(downloadId);
// Method to clean up temporary resumed files which is older than the given day
EPRDownloader.cleanUp(days);
DownloaderQueue.setRunningLimit(3); // set maximum number of concurrent downloads
int downloadId = Utils.getUniqueId(url, folderName + "/", fileName);
DownloadRequest download = DownloaderQueue.get(downloadId);
Other downloads in this FIFO queue will wait until they can meet conditions to start.
DownloaderQueue.add(download);
download = DownloaderQueue.get(downloadId);
DownloaderQueue.remove(downloadId);
This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details