DEV Community

Cover image for How to easily implement new In-App update feature to your Android App
Sanoj Punchihewa
Sanoj Punchihewa

Posted on

How to easily implement new In-App update feature to your Android App

Working all night to fix a bug or add a groundbreaking feature to your Android app and seeing only a few users have updated their apps? No worries now, Android have now released a new feature called in-app updates where you can prompt the user to update the app.


source: https://developer.android.com/guide/app-bundle/in-app-updates

Although some users enable background updates when their device is connected to an unmetered connection, other users may need to be reminded to update. In-app updates is a Play Core library feature that introduces a new request flow to prompt active users to update your app.

https://developer.android.com/guide/app-bundle/in-app-updates

As an Android developer, I felt tired adding all these codes to my apps. Thus I developed a library which will put in place the in-app update feature cutting down all the lines of code to 5 lines of code.

Let’s get started!

Implementation

Step 1: Add jitpack to your root level build.gradle at the end of repositories

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Add the dependency to app level build.gradle

dependencies {
    implementation 'com.github.SanojPunchihewa:InAppUpdater:1.0.2'
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Initialize the UpdateManager in your onCreate method of the Activity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initialize the UpdateManager
    UpdateManager.Builder().mode(UpdateManagerConstant.IMMEDIATE).start(this);

}
Enter fullscreen mode Exit fullscreen mode

There are two update modes as Flexible and Immediate,

  • Flexible(UpdateManagerConstant.FLEXIBLE) (default) — User can use the app during update download, installation and restart needs to be triggered by user
  • Immediate (UpdateManagerConstant.IMMEDIATE)— User will be blocked until download and installation is finished, restart is triggered automatically

Step 4: Call continueUpdate method in your onResume method to install waiting updates

@Override
protected void onResume() {
    super.onResume();
    UpdateManager.continueUpdate(this);
}
Enter fullscreen mode Exit fullscreen mode

Tadaa! That’s it. Now you have in-app updates in your android app

If this helped you please give some ❤️ to this article and ⭐️ the library

Since I released the library recently 😉, if you find any bugs or have a suggestion please raise an issue

Also if you find it hard to get working, leave a comment, I am always happy to help you 😃

Top comments (1)

Collapse
 
fsghasemi profile image
Fahime Ghasemi

Is it possible to implement in-app update for apps that published in HUAWEI AppGallery?