Support In-App-Updates Implementation Example

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,

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.

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

Senior Software Engineer at OpenLane Inc, Open source contributor at Mifos Initiative and mentoring GSoC Students. https://github.com/therajanmaurya