Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Using PRDownloader Library in your Android application
- Add this in your build.gradle
- ```groovy
- compile 'com.mindorks.android:prdownloader:0.2.0'
- ```
- Do not forget to add internet permission in manifest if already not present
- ```xml
- <uses-permission android:name="android.permission.INTERNET" />
- ```
- Then initialize it in onCreate() Method of application class :
- ```java
- PRDownloader.initialize(getApplicationContext());
- ```
- Initializing it with some customization
- ```java
- // 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
- ```java
- 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) {
- }
- });
- ```
- ### Pause a download request
- ```java
- PRDownloader.pause(downloadId);
- ```
- ### Resume a download request
- ```java
- PRDownloader.resume(downloadId);
- ```
- ### Cancel a download request
- ```java
- // Cancel with the download id
- PRDownloader.cancel(downloadId);
- // The tag can be set to any request and then can be used to cancel the request
- PRDownloader.cancel(TAG);
- // Cancel all the requests
- PRDownloader.cancelAll();
- ```
- ### Status of a download request
- ```java
- Status status = PRDownloader.getStatus(downloadId);
- ```
- ### Clean up resumed files if database enabled
- ```java
- // Method to clean up temporary resumed files which is older than the given day
- PRDownloader.cleanUp(days);
- ```
Add Comment
Please, Sign In to add comment