PostsNowPinterestTwitterGithub

Android In-App Update

Google In-App Update allows us to do two types of updates,

  1. Flexible Update
  2. Immediate Update

With flexible update if an update is available and we are doing it, a dialog appears to user to request consent. If the user consents, then the download starts in background, and user can continue using the app.

With Immediate update as well user shall consent to begin the update and Google Play will display a progress bar throughout the update and the app will restart, unlike with flexible update where we shall explicitly restart the app.

Read more about the implementation details here

How to check for new update?

Googles recommendation, to differentiate flexible or immediate update is have staleness check or use update priority.

An example for staleness check would be to do a flexible update after certain of an update being available.

appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
    if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
          && appUpdateInfo.clientVersionStalenessDays() != null
          && appUpdateInfo.clientVersionStalenessDays() >= DAYS_FOR_FLEXIBLE_UPDATE
          && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
              // Request the update.
    }
});

The other more soundingly flexible way is to use update-priority. It can be set between 0-5 and this gives us control to adjust which updates shall use flexible or immediate or neither. Also this can be used along with staleness check.

appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
    if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
          && appUpdateInfo.updatePriority() >= 4 /* high priority */
          && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
              // Request an immediate update.
    }
});

To do add update-priority to a release we shall use Play Developer API https://developers.google.com/android-publisher/tracks#apk_workflow_example and pass inAppUpdatePriority in Edit.tracks

{
  "releases": [
    {
      "versionCodes": ["88"],
      "inAppUpdatePriority": 5,
      "status": "completed"
    }
  ]
}

Adding inAppUpdatePriority with fastlane:

Pass in_app_update_priority as parameter to upload_to_play_store call within your release.

upload_to_play_store (
    in_app_update_priority: 5
)

or you can also pass it as key to fastlane supply

fastlane supply --aab path/app.aab --track beta --in_app_update_priority 3