Search code examples
androidandroid-app-bundlein-app-update

How to specify which updates need to be updated immediately and which ones are flexible with Google's in app update API?


I have followed the steps on Google's site to support in app updates. However I remain confused on how I specify which updates are "immediate" and which updates are "flexible". I do not see a flag anywhere in the Google Play Developer Console. Or am I supposed to write my own API to check on my server based on version code?

Here is my implementation:

        appUpdateManager.appUpdateInfo.addOnSuccessListener { updateInfo ->
        Log.e("launcher", "appUpdateInfo $updateInfo")
        Log.e("launcher", "updateAvailablility ${updateInfo.updateAvailability()}")
        Log.e("launcher", "availableVersion ${updateInfo.availableVersionCode()}")
        if (updateInfo.updateAvailability()
                == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
            // If an in-app update is already running, resume the update.
            appUpdateManager.startUpdateFlowForResult(
                    updateInfo,
                    IMMEDIATE,
                    this,
                    REQUEST_UPDATE);
        } else if (updateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && updateInfo.isUpdateTypeAllowed(IMMEDIATE)) {
            appUpdateManager.startUpdateFlowForResult(updateInfo, IMMEDIATE, this, REQUEST_UPDATE)
        } else if (updateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && updateInfo.isUpdateTypeAllowed(FLEXIBLE)) {
            dialog(getString(R.string.update_recommended_title), getString(R.string.update_required_content), getString(R.string.update_required_positive), {
                appUpdateManager.startUpdateFlowForResult(updateInfo, FLEXIBLE, this, REQUEST_UPDATE)
            }, getString(R.string.update_recommended_negative), {
            })

        }
    }

Solution

  • Today, you need to use your own API or encode it in the versionCode.