How to Use PRDownloader Library in Android App?
PRDownloader library is a file downloader library for android. It comes with pause and resumes support while downloading a file. This library is capable of downloading large files from the internet and can download any type of file like image, video, pdf, apk and etc. It provides many features that can help a user to download files from the internet easily and efficiently. With this library, you can also check the status of the downloading using the download id and can perform many other important operations using the download id. This library contains many important methods that give full control to the user to handle the downloading states of the file like pause, cancel, resume, etc. You can make the following Requests with this library:
Pause a download request:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Cancel a download request:
// 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();
Resume a download request:
Get status of a download request:
Status status = PRDownloader.getStatus(downloadId);
What we are going to build in this article?
A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.
Step By Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Then Enter your App Name in the Name field and select Java from the Language drop-down menu.
Step 2: Add dependency
To add the dependency navigate to app > Gradle Scripts > gradle.build(Module: app) and add the below dependency in the dependencies section. After adding the dependency sync your project.
Step 3: Add Internet Permission
Navigate to app > manifest > AndroidManifest.xml and add the internet permission.
Step 4: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
Below is the code for the Strings.xml file
Step 5: Designing the box layout
Navigate to app > res > drawable > right-click > new > Drawable Resource File and name that file as box_design_layout and add the below code to that file.
Step 6: Create Util class
Navigate to app > java > package name > right-click > New >Java class and name that file as Utils.java. Add the below code into Utils.java. Below is the code for Utils.java.
Step 7: Working with the MainActivity.java
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.