Skip to content

PRDownloader - A file downloader library for Android with pause and resume support

License

Notifications You must be signed in to change notification settings

tRuNKator/PRDownloader

 
 

Repository files navigation

PRDownloader

PRDownloader - A file downloader library for Android with pause and resume support

Mindorks Android Store Mindorks Mindorks Community License

Sample Download

Overview of PRDownloader library

  • PRDownloader can be used to download any type of files like image, video, pdf, apk and etc.
  • This file downloader library supports pause and resume while downloading a file.
  • Supports large file download.
  • This downloader library has a simple interface to make download request.
  • We can check if the status of downloading with the given download Id.
  • PRDownloader gives callbacks for everything like onProgress, onCancel, onStart, onError and etc while downloading a file.
  • Supports proper request canceling.
  • Many requests can be made in parallel.
  • All types of customization are possible.

Using PRDownloader Library in your Android application

Add this in your build.gradle

compile 'com.mindorks.android:prdownloader:0.5.0'

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 :

PRDownloader.initialize(getApplicationContext());

Initializing it with some customization

// Enabling database for resume support even after the application is killed:
PRDownloaderConfig config = PRDownloaderConfig.newBuilder()
                .setDatabaseEnabled(true)
                .build();
PRDownloader.initialize(getApplicationContext(), config);

// Setting timeout globally for the download network requests:
PRDownloaderConfig config = PRDownloaderConfig.newBuilder()
                .setReadTimeout(30_000)
                .setConnectTimeout(30_000)
                .build();
PRDownloader.initialize(getApplicationContext(), config); 

Make a download request

int downloadId = PRDownloader.download(url, dirPath, fileName)
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                               
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                               
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                               
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                               
                            }

                            @Override
                            public void onError(Error error) {
                               
                            }
                        });