Install or Update Android App Programmatically

To Install or Update android app programmatically is very simple and easy to implement. Android application can be updated without going through Google Play Store. We can download the apk file from the server and install it programmatically. An apk file will be downloaded by using HttpURLConnection class within AsyncTask. Once download is completed we will use Implicit Intent to install and open the downloaded apk file. We will create a sample project to demonstrate updating android app programmatically.

Download Source Code

Update Android App Programmatically – Implementation

Create a new Project in Android Studio with default settings and name it UpdateTutorial.

Add the Internet and WRITE_EXTERNAL_STORAGE permission in the MeniFest file. Internet permission is required for making Http call. We will store the downloaded apk on externet storage therefore we are adding WRITE_EXTERNAL_STORAGE permission.

Create a basic layout for MainActivity. Add a TextView and Button in activity_main.xml file. We will display app version in TextView and Button will be used to start the update process.


Add the below code in your main activity file.

As you see in the above code that we have created an AsyncTask sub class to make Http call to download the apk file.

Setting the URL of apk file. I have already uploaded the apk file on the server having a version no 2.

Making Http call using HttpURLConnect class

Create a Download directory on external storage.

Creating the instance of File class and delete app-debug.apk file if already exist.

We will read the data using InputStream class and write the data to the file by using FileOutputStream class. A stream is a sequence of data. InputStream is used for reading and OutputStream is used for writing.

After completing download and writing the data to the file we will use Implicit Intent to instal and open the downloaded apk file.

Now run the application. You will see the following output. I have already uploaded the apk file having version 2 now we will run the application with version 1.

update android-app-programitically

Update Android App Programmitically – Video Demo

I hope you will like this tutorial. Subscribe to our Newsletter to get new articles and tutorials in your inbox as soon as they published. You can connect with us on Facebook and also subscribe to our Youtube Channel.

Check Also

Kotlin SQLite Database Tutorial With Example

A step by step tutorial for implementing SQLite database in Kotlin. I will implement all …