How To Update Android Apk Outside The Playstore

How to update android apk outside the playstore

Let’s learn how to update android apk outside the playstore in this short post! Perhaps you have a scenario where you don’t want to publish your app in the playstore. The reason behind your decision could be to have more control over who installs the app or even the size of the file itself among other things.

Without publishing your apps through the playstore however, you are left with the responsibility of updating your own apps, keeping track of total downloads, managing the app from start to finish, handling payments (for paid-for apps) among other good things that come with Google Playstore! In this post, I will show you how to update your apps outside the playstore system. That means the updates are pushed automatically to the users who currently have the app installed! Let us get started, shall we?

How to update android apk outside the playstore – Steps

  • You first upload your new apk to your own server somewhere in the north pole or your basement (if you still live with your parents and they have allowed you to have your server there)
  • Make an HTTP GET request to a URL that will return the data back to you for instance by visiting http://yoursite.com/apk

Show me the codez son…

For demonstrative purposes ONLY, I am going to use an AsyncTask in this post to show you how to update android apk outside the playstore. There are better ways to perform network operations in android like using Retrofit – my favorite library FYI! Let us take a look here:

ApkUpdateAsyncTask.java

How to actually use this code

Once you have your AsyncTask cooked up and ready to serve, you can easily execute it like this:

That is all you need to update your apk outside the playstore. Remember, you have to implement a way to check that the version codes differ before running updates. That means, you could check a value that gets updated whenever a new apk is uploaded remotely on your server to see if the version of the app has been updated, then make the second HTTP request to pull down the new apk file!

If you found this post helpful, please consider sharing with others using the buttons below and subscribing for more posts on different topics! Got questions? Comments? Suggestions? Let me know below!

Thanks again for reading my post – always stay awesome!

 

Written By Elisha Chirchir

Elisha Chirchir is a software developer. He is also the founder of Simple Developer and co-founder of Instinctive Software Solutions. On any given day, he works on both Android and Web Development. During his 'free time', he offers training to those interested in learning how to code in php, java, python, javaScript etc. You can easily find him on StackOverflow Android chatroom or on Twitter @Eenvincible

8 Comments on “How To Update Android Apk Outside The Playstore

  1. peter Reply

    June 4, 2016 at 3:31

    great tips!! added to the bookmarks of eternity

  2. mark anthony elbambo Reply

    January 27, 2017 at 11:02

    This only work on a rooted/system apps right? Is it possible to also do in a regular app?

    • Elisha Chirchir Reply

      January 30, 2017 at 7:46

      It works on all devices – both rooted and non-rooted!

  3. Amit Reply

    February 21, 2017 at 6:44

    Not working . Getting error as::

    I/onPostExecute: Error running exec(). Command: [su] Working Directory: null Environment: null

  4. Koundalmadan Reply

    April 10, 2017 at 7:14

    Pls

  5. Koundalmadan Reply

    April 10, 2017 at 7:15

    Yh version bhut hi achha hai

  6. chetan Reply

    March 19, 2018 at 6:06

    got same error : I/onPostExecute: Error running exec(). Command: [su] Working Directory: null Environment: null

  7. sam Reply

    April 26, 2018 at 2:27

    Can You please add the update checker to my code, if there is new version prompt the user to install it, Cause i searched a lot in the web without specific solution.
    This code detects if the package is installed and launch it, and if not it download it directly from my URL.
    i’m using facebook lite as an example here.
    Thanks.

    //============================

    MyButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

    ///// check if package name is installed //////////

    final String YOUR_PACKAGE = “com.facebook.lite”;
    PackageManager packageManager = getPackageManager();
    ApplicationInfo applicationInfo = null;
    try {
    applicationInfo = packageManager.getApplicationInfo(YOUR_PACKAGE, 0);
    } catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
    }
    if (applicationInfo == null) {

    ///// If Not installed it will open your app directly from Url
    Update(“https://www.dropbox.com/s/jqqbp5eazfs6hto/facebook.apk?dl=1”);

    } else {
    // Open the app If Installed
    Intent LaunchIntent = packageManager.getLaunchIntentForPackage(YOUR_PACKAGE);
    startActivity(LaunchIntent);

    }
    }
    });

    ///// =*=*=**=*==*=*=**=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

    }

    @SuppressLint(“StaticFieldLeak”)
    public void Update(final String apkurl) {
    new AsyncTask() {
    String result = “”;

    @Override
    protected String doInBackground(Void… params) {
    try {
    URL url = new URL(apkurl);
    HttpURLConnection c = (HttpURLConnection) url
    .openConnection();
    c.setRequestMethod(“GET”);
    c.connect();
    String PATH = Environment.getExternalStorageDirectory()
    + “/download/”;
    File file = new File(PATH);
    file.mkdirs();
    File outputFile = new File(file, “facebook.apk”);
    FileOutputStream fos = new FileOutputStream(outputFile);

    InputStream is = c.getInputStream();
    byte[] buffer = new byte[1024];
    int len1 = 0;
    while ((len1 = is.read(buffer)) != -1) {
    fos.write(buffer, 0, len1);
    }
    fos.close();
    is.close();
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + “/download/” + “facebook.apk”)),
    “application/vnd.android.package-archive”);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

    } catch (IOException e) {
    result = “Update error! ” + e.getMessage();
    e.printStackTrace();
    }
    return result;
    }
    protected void onPostExecute(String result) {
    }
    }.execute();
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *