Update and Install Your Android App From Your Own Server Programmatically

In this post, we will see how to update and install your android app from your own server. I will discuss only important coding part. Suppose you are working in small organisation with member of 30 to 50 members. All members using  the company’s app. It’s not a good way to upload your app on Google Play Store for targeting only 30 to 50 devices. Also you have to pay money to Google play store to upload your app. You can use Google play Store if you are targeting large users to use your app. But , if you are working with small team then you have to use your own server if you want to save your money !

Simple logic and steps involved to update and install your android app from your own server:

  1. You must have your own server.
  2. Create HTTP connection between app client and server.
  3. Compare version of app client and and available app on server.
  4. If the version of app on server is higher then show alert popup message on client app to download and install latest app.

We will see here all steps in detail:

MainActivity.java :

I have created object ‘alarm’ of class SampleAlarmReceiver. It is used to check new version of app available or not on server. We are running this service for every 5 minutes.



This BroadcastReceiver automatically restarts the alarm when the device is rebooted.


onReceive SampleSchedulingService will start. Here it is the actual code :

Versioning is important to maintain your app upgrade strategy. BuildConfig.VERSION_CODE will show the version code of your app. You can see in build.grandle:

On every update you have to increase the  value of versionCode in build.grandle. Higher number indicates more recent version of app.

We are sending this version number using HTTP POST method to server to compare latest version availability on server. Here HttpURLConnection is used to perform HTTP data request and response. If the response string value is higher than current versionCode then new activity(ShowNote.java) will open using Intent.


In above code , if latest update available on server then it will show AlertDialog. If user clicks on OK then it will download and installs the app. I will not discuss whole code . Code is itself explanatory.

AlertDialog After latest version available on server
AlertDialog After latest version available on server

Also I have mentioned rooting concept here in above code. Rooting means your device will allow to access to change  the software code on the device or install other software(specially custom ROM) that the manufacturer wouldn’t normally allow you to. Please don’t try to root your device . It may harm your device. Generally people root their device to upgrade latest android OS(marshmallow ,nougat or other activity on device).

Come on coding part, if your device is rooted then app will download and update automatically in background.

Above command will execute to direct installation of app without taking extra permissions from user.

If your device is not rooted then it will show to user a installation dialog with app permissions like normal app installation.

App Installation Request on non-rooted device
App Installation Request on non-rooted device

version.php :

Put your latest updated app on same directory of server.Note that you have to  increment versionCode on client app after each update.

Create a text file updateVersion.txt on same server directory. Write here same versionCode that you already mentioned on updated  app. I have created this file only send HTTP response to app client in JSON format.

It is simple way to Update and Install Your Android App From Your Own Server Programmatically. Later you can add your own functionality to track total downloads, how many user installed latest version. But you have to create a web interface to show all data on web page. Use any language like PHP, Node.js or Python to create web application to track this all record. If you have any question then don’t forget to comment below.






Leave a Reply


    1. When you update app then change ‘versionCode’ in build.grandle with higher integer number than previous value. Upload your app on server. Put version.php and updateVersion.txt file on same directory. Now change the versionCode in updateVersion.txt. Just enter integer number that matches with your updated version of app. for example see here http://prntscr.com/lthir0

      1. Thank you so much for the swift response.
        I did what you suggested. But, I run version.php on my xampp to see the output… I get an error “Trying to get property of non-object in version.php on line 5”

        1. :You will get ‘Notice’ if you are running code on local XAMPP. In this case just put @ symbol on line 5 : e.g:

          If you try code on actual server then it will work perfectly.

  1. Please Show me the Manifest File. Showing some errors.

    Caused by: java.lang.IllegalArgumentException:
    Component class com.vr.appupdate.SampleBootReciver does not exist in com.vr.appupdate
    at android.os.Parcel.readException(Parcel.java:2009)
    at android.os.Parcel.readException(Parcel.java:1951)
    at android.content.pm.IPackageManager$Stub$Proxy.setComponentEnabledSetting(IPackageManager.java:4785)
    at android.app.ApplicationPackageManager.setComponentEnabledSetting(ApplicationPackageManager.java:2299)
    at com.vr.appupdate.SampleAlarmReceiver.setAlarm(SampleAlarmReceiver.java:43)
    at com.vr.appupdate.MainActivity.onCreate(MainActivity.java:13)

    My Manifest file:

    1. Hello Tuna,

      Currently I don’t have separate source code. It’s working code. I tried in simple way how implement logic in this post. Please understand above steps, logic, code and build your ‘own’ code 🙂

  2. Strange thing :/ I’ve added everything to project, all this java files are in same package as rest of app files. But when I try to run on emulator app crashes instantly with exception java.lang.RunetimeException (IllegalArgumentException: Component class (myComponentName).SampleBootReceiver does not exist in (myComponentName).
    When I comment out in my MainActivity line ‘alarm.setAlarm(this);’ my app is working fine (as it should because no new code was invoked).
    Any idea why I got this ‘does not exist’ error ? File is exist, it’s name is correct..

    1. Hey, You must add section receiver to manifest file with name .SampleBootReceiver. (Look at dot at filename first character!)