How to Build PDF Downloader App in Android with Kotlin?
Last Updated :
28 Apr, 2025
If you are creating apps for students or for educational purposes then you need to add some PDF files for displaying some data inside our app. These PDF files are updated on regular basis. A sample video is given below to get an idea about what we are going to do in this article.
In this article, we will build an application to help users download notes in pdf format.
Step by Step Implementation
Step 1: Create a New Project in Android Studio
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.
Step 2: Add Internet Permission in the AndroidManifest.xml file
XML
<uses-permission android:name="android.permission.INTERNET"/>
Step 3: Create Firebase ProjectÂ
Although we are not connecting firebase with the android studio we will be using it as a medium of storage. Go to the firebase website and click go to console and create a new firebase project. After that go to firebase storage here you will get the option to upload pdf files click on that upload button in order to upload files from your system. Click on the pdf uploaded by you in order to generate a pdf URL like this.
Step 4: Design layout Files
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. In activity_min.xml we are just adding a RecyclerView. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Since we are using recycler view we need to create a new layout file for that go to res->layout and create a new Layout resource file named item_layout.
item_layout file
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="5dp">
<ImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/pdf_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/pdf"/>
<TextView
android:id="@+id/subj_name"
android:layout_width="match_parent"
android:layout_height= "match_parent"
android:text="System Design Notes"
android:textSize="20sp"
android:textAlignment="center"
android:padding="30dp"
android:textStyle="bold"
android:textColor="@color/black">
</TextView>
</LinearLayout>
Step 5: Create Notes classÂ
Kotlin
class Notes
( var image : Int
, var subj_name : String
,var url : String?
)
Step 6: Create NotesAdapter class
Since we are using recycler view therefore we will create an adapter class. Â We will also use the concept of Download Manager in order to download notes in pdf format.
Kotlin
class NotesAdapter( var data: ArrayList<Notes>, var context: Context) : RecyclerView.Adapter<NotesAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layout = LayoutInflater.from(context).inflate(R.layout.item_layout, parent, false)
return ViewHolder(layout)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.name.text = data[position].subj_name
holder.image.setImageResource(data[position].image)
holder.itemView.setOnClickListener{
var download= context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
var PdfUri = Uri.parse(data[position].url)
var getPdf = DownloadManager.Request(PdfUri)
getPdf.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
download.enqueue(getPdf)
Toast.makeText(context,"Download Started", Toast.LENGTH_LONG).show()
}
}
override fun getItemCount(): Int {
return data.size
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
internal val name: TextView
internal val image: ImageView
init {
name = itemView.findViewById(R.id.subj_name)
image = itemView.findViewById(R.id.pdf_image)
}
}
}
Step 7: Working with the MainActivity.kt file
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
Kotlin
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val item = ArrayList<Notes>()
item.add(
Notes(
R.drawable.pdf,
"System Design",
"https://firebasestorage.googleapis.com/v0/b/online-learning-ea8c0.appspot.com/o/Uploads%2FSystem%20Design%20Basics%20Handbook%20-8.pdf?alt=media&token=084ec8ce-598a-4a14-ad7c-61003e509af6"
)
)
item.add(
Notes(
R.drawable.pdf,
"DBMS",
"https://firebasestorage.googleapis.com/v0/b/online-learning-ea8c0.appspot.com/o/Uploads%2Fdbms_tutorial%20(1).pdf?alt=media&token=7e8a8500-5c94-4b03-a088-3b071d8b35e1"
)
)
item.add(
Notes(
R.drawable.pdf,
"C Notes",
"https://firebasestorage.googleapis.com/v0/b/online-learning-ea8c0.appspot.com/o/Uploads%2F%5BStudycrux.com%5D%20Let%20us%20C%20by%20Yashwant%20Kanetkar%20(1).pdf?alt=media&token=671c6f65-26f1-4524-ac23-66e321aa5db1"
)
)
item.add(
Notes(
R.drawable.pdf,
"Resume",
"https://firebasestorage.googleapis.com/v0/b/online-learning-ea8c0.appspot.com/o/Uploads%2F%5BStudycrux.com%5D%20Let%20us%20C%20by%20Yashwant%20Kanetkar%20(1).pdf?alt=media&token=671c6f65-26f1-4524-ac23-66e321aa5db1"
)
)
val recycler_view = findViewById<RecyclerView>(R.id.recycler_view)
recycler_view.layoutManager = LinearLayoutManager(applicationContext)
val adapter = NotesAdapter(item,this)
recycler_view.adapter = adapter
}
}
Output:
Similar Reads
How to Build a Simple Torch App in Android using Kotlin?
Torch Application is a very basic application that every beginner level android developer should definitely try to build while learning Android. In this article, we will be creating an application in which we will simply display a toggle button to switch on and switch off the torch. Note: If you are
4 min read
Convert WebView to PDF in Android with Kotlin
Sometimes the user has to save some article that is being displayed on the web browser. So for saving that article or a blog users can simply save that specific web page in the form of a PDF on their device. We can implement this feature to save the pdf format of the web page which is being displaye
5 min read
How to Download Free Apps on Android?
Downloading free apps on your Android device is a simple process that can greatly enhance your smartphone experience. With millions of apps available on the Google Play Store, you can find tools, games, productivity apps, and much more without spending a dime. In this guide, we will walk you through
3 min read
Calendar View App in Android with Kotlin
Calendar View is seen in most travel booking applications in which the user has to select the date of the journey. For the selection of the date, this view is used. In this article, we will take a look at How to implement Calendar View within our Android application using Kotlin. A sample video is g
3 min read
How to Generate a PDF file in Android App?
There are many apps in which data from the app is provided to users in the downloadable PDF file format. So in this case we have to create a PDF file from the data present inside our app and represent that data properly inside our app. So by using this technique, we can easily create a new PDF accor
6 min read
How to Create Video Player and Downloader App in Android?
In this article, we will walk you through the process of creating a simple video player and downloader app in Android using Kotlin and Android Studio. In this project, we will use firebase to store videos and generate URLs. A sample video is given below to get an idea about what we are going to do i
3 min read
Kotlin Flow in Android with Example
Kotlin Flow is a tool that helps developers work with data that changes over time like search results, live updates, or user input. Itâs part of Kotlinâs coroutines, which are used for writing code that doesnât block the app while waiting for something to finish, like a network call or a file to loa
8 min read
How to Build a Simple Notes App in Android?
Notes app is used for making short text notes, updating when you need them, and trashing when you are done. It can be used for various functions as you can add your to-do list in this app, some important notes for future reference, etc. The app is very useful in some cases like when you want quick a
9 min read
How to Draw Border on Event of Click in Android with Kotlin?
Sometimes we want to display to the users that they have clicked an item by showing a border on the item. So, for this, we need to create two drawable resource files, one for the normal background of the item and another for the border. A sample video is given below to get an idea about what we are
3 min read
How to Build Android Applications with Gradle?
There are several contemporary build automation technologies available nowadays that may be utilized to create a quicker build when creating a project. Gradle is one of these modern-day automation technologies. Gradle is now used by Android to automate and control the build process while also defini
8 min read