In-App Update Feature

Updated 11 October 2021

Save

In-App Update (Android)

In this blog, we are going to learn about the In-App Update feature in Android. Well, there are surely some benefits of using the In-App Update feature. You must be wondering why and how?

Well, we always want our customers or users to update their application if there is a new version available. As I live in India where most people turned off their auto update from google play store for several reasons therefore if there is a new version available they will not able to know.

That’s where this library comes into play. Now you can easily prompt the user to update the application if the user allows then you can update the application. With the In-App update feature, the user can also interact with the application. Now the user doesn’t have to explicitly go to google play store to check for any update available for that application.

 

How to use In-App Update feature

An In-app update is introduced as a part of the Play Core Library, which actually allows you to prompts the user to update the application when there is any update available on the Google Play Store.

There are two modes to use an In-app update feature.

  1. Flexible Update
  2. Immediate Update

Flexible Update:

In Flexible update, the dialog will appear and after the update, the user can interact with the application. This mode is only recommended to use when there is no critical or core change applied to your application.

Immediate Update:

In Immediate Update, the full-screen UI shows in our application and this is best to use when there is critical core functionality is getting affected and when the immediate update is selected the user can’t interact with the application and after the update, the application gets restarted.

Let’s Start the implementation

  1. Add the Google Play Core Dependency on your android build.Gradle(app) :
  2. Create an instance of the AppManager to get the in-app update info.
  3. To get the monitor the update the InstallStateUpdatedListener is used, so that when the update can be installed. Register the listener before starting the update.:

     
  4. Now we need to check if the update is available or not (Use this method on the onStart() method of the Activity).

    In the above code, I created a function with the name checkForAppUpdate() in this the updateManager will get the app update information which we have instantiated with AppUpdateManagerFactory.create(this). After that, we are just getting the app update information using updateManager.appUpdateInfo. This will provide the information for the application. Now after that, we are using addOnSuccessListener we need to first check If the update available or not with the function updateAvailability() this will return the Boolean value, and check the mode Flexible / Immediate. If both the condition met then we have the update available therefore we can start the process. To get the monitor the update the InstallStateUpdatedListener is used, so that when the update can be installed. Register the listener before starting the update.:
  5. Un-Registering the Listener after there is no need longer for the listener, to avoid the memory leak.

     
  6. After monitoring the update status and you detect the InstallStatus.DOWNLOADED state. Now you need to restart the app to install the update so for that we need to just call completeUpdate() function, We are using this inside the updateSnakeBarForComplete() method:

     
  7. Getting the result on onActivityResult:

     

 

For Testing

You have to Generate the signed APK or bundle and then go to App-Internal-Sharing in the Play Console and upload the build and after that, you can quickly share an app bundle or APK with your internal team and testers to test the build.

 

Or


On your test device, make sure you’ve already installed a version of the app using an internal app sharing URL and the device supports in-app updates then it uses a version code that’s lower than the updated version of your app.

. . . . . . . . .

That’s it from my side for today, thanks for reading it until now. If you want to read more about, check out the official developer documentation below:

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

author
. . .

Leave a Comment

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


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home