Image for post
Image for post

Support In-App-Updates Implementation Example

Rajan Maurya
Feb 6 · 4 min read

In-App-Updates Example -> https://github.com/therajanmaurya/In-App-Update-Example

Recently I was working on In-App-Updates. When you will see the documentation: https://developer.android.com/guide/playcore/in-app-updates. It would look like that it is straight forward and you don’t have to write anything extra but no…

If you will think about the UX, you have to handle every event through UI.

whenever onStateUpdate will be invoked. These events,

public @interface InstallStatus {

public static final int CANCELED = 6; // 0x6

public static final int DOWNLOADED = 11; // 0xb

public static final int DOWNLOADING = 2; // 0x2

public static final int FAILED = 5; // 0x5

public static final int INSTALLED = 4; // 0x4

public static final int INSTALLING = 3; // 0x3

public static final int PENDING = 1; // 0x1

public static final int UNKNOWN = 0; // 0x0
}

In-App-Updates API works in background but still, you have to show particular UI to the user to download the update or install the update, If there is no update is available then hide the whole update UI.

Image for post
Image for post

Implementation

Now Let’s implement Initially, you have to add the UI, here you can use this UI if you want, it’s up to you if you want to change it you can.


Next Add InAppUpdateUtils class


Now it’s time to add initialize the InAppUpdateUtils in MainActivity (I prefer in Dashboard activity)

Cool, You are done. The above code will check for updates and show the proper UI accordingly.

Test with internal app-sharing

I know you would have question about the testing, so you will be relieved that above code works perfectly.

With internal app sharing, you can quickly share an app bundle or APK with your internal team and testers by uploading the app bundle you want to test to the Play Console.

You can also use internal app sharing to test in-app updates, as follows:

  1. On your test device, make sure you’ve already installed a version of your app that meets the following requirements:
    - The app was installed using an internal app sharing URL
    - Supports in-app updates
    - Uses a version code that’s lower than the updated version of your app
  2. Follow the Play Console instructions on how to share your app internally. Make sure you upload a version of your app that uses a version code that’s higher than the one you have already installed on the test device.
  3. On the test device, only click the internal app-sharing link for the updated version of your app. Do not install the app from the Google Play Store page you see after clicking the link.
  4. Open the app from the device’s app drawer or home screen. The update should now be available to your app, and you can test your implementation of in-app updates.

Troubleshoot

This section describes some possible solutions to situations where in-app updates might not work as expected during testing.

  • In-app updates are available only to user accounts that own the app. So, make sure the account you’re using has downloaded your app from Google Play at least once before using the account to test in-app updates.
  • Make sure that the app that you are testing in-app updates with has the same application ID and is signed with the same signing key as the one available from Google Play.
  • Because Google Play can only update an app to a higher version code, make sure the app you are testing as a lower version code than the update version code.
  • Make sure the account is eligible and the Google Play cache is up to date. To do so, while logged into the Google Play Store account on the test device, proceed as follows:
  1. Make sure you completely close the Google Play Store App.
  2. Open the Google Play Store app and go to the My Apps & Games tab.
  3. If the app you are testing doesn’t appear with an available update, check that you’ve properly set up your testing tracks.

Thanks For Reading, If you have any question. Please ask , I would love to answer.

Rajan Maurya

Written by

Lead Android Developer at https://idtlabs.xyz, Open source contributor at Mifos Initiative and mentoring GSoC Students. @GitHub: https://github.com/thera

Rajan Maurya

Written by

Lead Android Developer at https://idtlabs.xyz, Open source contributor at Mifos Initiative and mentoring GSoC Students. @GitHub: https://github.com/thera

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store