Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What purpose does appUpdateInfo.isUpdateTypeAllowed (AppUpdateType.IMMEDIATE) serve in Android In-App Update API?

I have been following In-App update API in Android for quite some time now and I am unable to find any relevance of the following line:

appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)

--

appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)

This isUpdateTypeAllowed() method has been used in the code snippet below in Android Documentation: https://developer.android.com/guide/app-bundle/in-app-updates#update_readiness. Moreover, the above two method calls return true in all the cases and I am unable to find a case for which any of the above two method calls return false.

like image 589
Abhishek Luthra Avatar asked May 30 '19 12:05

Abhishek Luthra


People also ask

What is in-app update?

In-app updates is a Google Play Core libraries feature that prompts active users to update your app. The in-app updates feature is supported on devices running Android 5.0 (API level 21) or higher. Additionally, in-app updates are only supported for Android mobile devices, Android tablets, and Chrome OS devices.


2 Answers

These methods will always return true when there is a new update on playstore and current app version on device is less than the app version on playstore. To identify whether update is Flexible or Immediate we need to set a flag for FLEXIBLE or IMMEDIATE UPDATE in Remote Config like {"upgradeType":0/1} where 0 = FLEXIBLE and 1 = IMMEDIATE. For now we don't have any option in playstore console to set a flag for FLEXIBLE or IMMEDIATE update while releasing a build so for now we can set flag using remote config and identify whether update is FLEXIBLE or IMMEDIATE, might be in future playstore will give an option to set flag to identify for type of update.

Code:

val jsonObject=JSONObject(FirebaseConfig().getStringConfig(RemoteConfigConstants.KEY_APP_UPGRADE))
updateFlag = jsonObject.getInt(JsonConstants.UPGRADE_TYPE)

private fun checkForInAppUpdate() {
        appUpdateManager = AppUpdateManagerFactory.create(this)
        appUpdateManager.appUpdateInfo.addOnSuccessListener {
            if ((it.updateAvailability() === UpdateAvailability.UPDATE_AVAILABLE)) 
        {
                if (updateFlag == 0 && it.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
                    requestUpdate(it)
                    appUpdateManager.registerListener(this@HomeActivity)
                } else if (it.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                    requestUpdate(it, AppUpdateType.IMMEDIATE)
                }
            }
        }
    }

Here updateFlag value is the value we are getting from remote config for particular type of update.

like image 73
rahul sharma Avatar answered Sep 17 '22 02:09

rahul sharma


I had already raised this issue in Google Issue Tracker here and I did receive response from the Google Developers as follows :

It is up to the developer to choose which type of update is invoked. The mode is determined by the app in code. Please see https://developer.android.com/guide/app-bundle/in-app-updates#start_update

I have already integrated in-app update api in GoIbibo Mobile Application and It is running all perfect now. The documentation had this ambiguity. So you should write your own logic whether you want Flexible or Immediate Update.

like image 24
Abhishek Luthra Avatar answered Sep 19 '22 02:09

Abhishek Luthra