20

Working with google's new feature in-app update I noticed it seems to return old (previous) update info rather than correct newest one.

Android introduced new force update feature some time ago: https://developer.android.com/guide/app-bundle/in-app-updates called in-app updates

Working with it I noticed that when obtaining app update info according to google's tutorial the returned app version code sometimes is not up-to-date with version code of app available in store (has a previous updates info). It strongly looks like the app update info we request in code is take from cache rather than real google play store services.

val appUpdateManager = AppUpdateManagerFactory.create(context)
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
appUpdateInfoTask.addOnCompleteListener { task ->
   when {
      task.isSuccessful -> {
         val appUpdateInfo = task.result
         //the successful app update info may have old (previous) info 
         [...]
      }
      [...]
   }
}

When we decide to activate the force update flow app will be updated to wrong version, even when there is available higher version of app in store.

Exploring the subject deeper I found out that, when perform update on any other app via Google Play Store, our action will trigger cache refresh and next time the in-app update flow returns correct values and updates to correct app update.

Does anyone have any idea how to obtain correct (newest) available app version code via in-app update or force refresh play store cache programatically?

UPDATE:

I had a change to talk with google dev about this case on one of the conferences. From what he said there is no way to trigger programmatically Google Play's listing update (information about available updates) - user have to manually enter it and then the listing is updated. Google Play's cache last for 24h and I was told Google Play should refresh it's listing then.

Artur Kasprzak
  • 5,938
  • 3
  • 9
  • 13
  • 1
    I am running into this issue and am speechless at how this is buried in the bottom of their troubleshoot section. My personal device is a Samsung S8, and the version code I was getting back was a month old. I noticed my device has the play store blocked from running in the background as a battery optimization setting, I am sure many users do the same thing. This will make it very difficult to use this library and force update users. – parkgrrr Jun 02 '20 at 22:08

1 Answers1

1

The cache has to expire. It lasts 24h, then check for the update again.


Clear the Google Play Store Cache programmatically.

val packageManager = context.packageManager
val googlePlayStorePackageName = "com.android.vending"
try {
    packageManager.getPackageInfo(googlePlayStorePackageName, 0)
    // The Google Play Store is installed
    val googlePlayStoreAppInfo = ...
    val cacheDir = ...
    val cacheFiles = ...
    for (cacheFile in cacheFiles) {
        cacheFile.delete()
    }
} catch (e: PackageManager.NameNotFoundException) {
    // The Google Play Store is not installed
}

The code gets Google Play Store package info and deletes all cache.


Force Google Play Store refresh programmatically.

val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("market://details?id=<your_app_package_name>")
startActivity(intent)

The code launches Google Play Store, triggers an app refresh and update the info.

This approach isn't be suitable because the user has interaction with Google Play Store.


Use Google Play Developer API and provide access through programming method. You have to set authentification and an authorization for API.


Implement a cache system. You require to manage cache by a mechanism to store app's update information. In this solution you have to manage the cache. Use OkHttp or Retrofit to implement the cache mechanism.


Use Third-party library like : In-App Update Manager, AppUpdater, UpdateChecker.

The libraries have a simple interface to manage the app to avoid cache issues.


These approaches work for me. Use and test them before deploying to prod.