Do somthings

In this article, we will learn about the In-app update feature in Android what is all about In-app updates, and what are the benefits of using the In-app update in your android application. Recently I’ve been working on a product in which I need to Implement an In-app update Why do we need to Implement this?

As a Developer we always want our users to have the updated version of their application but there are a lot of people who actually turned off their auto update from the google play store and he/she doesn’t know about any update available or not.

To overcome the problem Google Introduced this feature called In-app update from this feature you can easily prompt the user to update the application and with the user’s permission you can update the application also while updating the app user can able to interact with the application. Now the user doesn’t need to go to the google play store to check if there is any update available or not.

What is In-App Update:

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

There are two modes of an In-app update.

  • Flexible Update
  • 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 recommended to use when there is no major change In your application like some features that don’t affect the core functionality of your application.

The update of the application is downloading in the background in the flexible update and after the completion of the downloading, the user will see the dialog in which the user needs to restart the application. The dialog will not automatically show, we need to check and show to the user and we will learn how later.

Example Of Flexible Update:

Immediate Update:

In Immediate Update, the fullscreen UI comes up in our application and the user can’t interact with the application after the update the application restarted it-self and updated the application.

This mode is recommended when your app update affects directly the core functionality, Like when you have any critical update, so this mode we need to use.

Example Of Immediate Update:

Implementation:

Let’s start with the In-App update implementation, what we need to do first.

Step 1: Add Dependency

Add the Google Play Core Dependency to your android build.gradle file, like the below code snippet. and click Sync Now

implementation 'com.google.android.play:core:1.6.4'

Step 2: Create an AppManager Instance

We need to add this code in Home activity where you show user to the notification box for the update is available in play store.

AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);

// Returns an intent object that you use to check for an update.
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// This example applies an immediate update. To apply a flexible update
// instead, pass in AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
// Request the update.
try {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, MainActivity.this, Request_code);

} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
});

Request Code:

private final int Request_code = 111;

In this line, you can also use FLEXIBLE for replacing IMMEDIATE.

Flexible means the user can cancel the new update functionality and the app update will be postponed.

appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, MainActivity.this, Request_code);

Conclusion

This article taught you how to Implement an in-App update in your android application with two different modes, one is Flexible and one is Immediate, how you can request again, and how to monitor the status of the update.

I hope this article is helpful. If you think something is missing, have questions, or would like to offer any thoughts or suggestions, go ahead and leave a comment below. I’d appreciate the feedback.

I’ve written some other Android-related content, and if you liked what you read here, you’ll probably also enjoy these. I will explain my code in the videos also in the youtube here will be link:

https://www.youtube.com/channel/UChgThKMrEVXIdGe_KYKuciw

Categories: Android