1

I want to integrate flexible updates in my app. Here is my code:

fun checkForUpdates(){

    val appUpdateManager = AppUpdateManagerFactory.create(this)
    val appUpdateInfoTask = appUpdateManager.appUpdateInfo


    val listener = InstallStateUpdatedListener {

        if (it.installStatus() == InstallStatus.DOWNLOADED){

            val snackBar = Snackbar.make(parentLayout, "An update has just been downloaded.", Snackbar.LENGTH_INDEFINITE)
            snackBar.duration = 10000
            snackBar.view.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
            snackBar.setActionTextColor(ContextCompat.getColor(this, R.color.white))
            snackBar.setAction("RESTART") {
                appUpdateManager.completeUpdate()
            }
            snackBar.show()
        }
    }


    appUpdateInfoTask.addOnSuccessListener { appUpdateInfo->
        if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)){
            appUpdateManager.registerListener(listener)
            appUpdateManager.startUpdateFlowForResult(
                appUpdateInfo,
                AppUpdateType.IMMEDIATE,
                this,
                UPDATE_REQUEST_CODE)

        }
    }
}

I am facing problem with testing it. I tried decreasing my build version number but it doesn't seems to work.

Shunan
  • 3,165
  • 6
  • 28
  • 48

1 Answers1

0

As noted in the docs:

  • 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.
  • 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
  • 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.

See docs for more info

tenprint
  • 1,123
  • 1
  • 11
  • 29