In app update not working despite having an update
Asked Answered
B

0

8

I am trying to implement In App Update in my app, so that when there is a new update, user get to see it.

I have carefully followed all the steps listed here - https://developer.android.com/guide/playcore/in-app-updates/kotlin-java

But for some reasons, the dialog to update not showing...

Activity.kt

override fun onCreate(savedInstanceState: Bundle?) {

    setTheme(R.style.Theme_DirectMusicPlayer)
    super.onCreate(savedInstanceState)
    initViews()
    setContentView(binding.root)
}


private fun initViews(){
    checkForUpdate()
}

 private fun checkForUpdate(){

    appUpdateManager = AppUpdateManagerFactory.create(this)

    // Returns an intent object that you use to check for an update.
    val appUpdateInfoTask = appUpdateManager.appUpdateInfo

    // Checks that the platform will allow the specified type of update.

    appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->

        if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE

           {

            // Request the update.
            appUpdateManager.startUpdateFlowForResult(
                // Pass the intent that is returned by 'getAppUpdateInfo()'.
                appUpdateInfo,
                // Or 'AppUpdateType.FLEXIBLE' for flexible updates.
                AppUpdateType.FLEXIBLE,
                // The current activity making the update request.
                this,
                // Include a request code to later monitor this update request.
                Constants.MY_REQUEST_CODE
            )
        }
        else{
            Toast.makeText(this, "No update yet", Toast.LENGTH_LONG).show()
        }
    }
    //Create a listener to track request state updates.
    installStateUpdatedListener = InstallStateUpdatedListener { state ->

        when (state.installStatus()) {

            InstallStatus.DOWNLOADING -> {
                val bytesDownloaded = state.bytesDownloaded()
                val totalBytesToDownload = state.totalBytesToDownload()

                //show download progress
            }

            InstallStatus.DOWNLOADED -> {
                //show SnackBar
                showInstallSnackBar()
            }
            InstallStatus.INSTALLED -> {
                appUpdateManager.unregisterListener(installStateUpdatedListener)
            }

            else -> {
                //do something
            }
        }
    }

    // Before starting an update, register a listener for updates.
    appUpdateManager.registerListener(installStateUpdatedListener)


}


private fun showInstallSnackBar(){

    Snackbar.make(
        findViewById(android.R.id.content),
        "An update has just been downloaded.",
        Snackbar.LENGTH_INDEFINITE
    ).apply {
        setAction("RESTART") { appUpdateManager.completeUpdate() }
        setActionTextColor(ContextCompat.getColor(this@PermissionActivity, R.color.app_name_color))
        show()
    }

}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

    super.onActivityResult(requestCode, resultCode, data)

    if (requestCode == Constants.MY_REQUEST_CODE) {
        if (resultCode != AppCompatActivity.RESULT_OK) {
            // If the update is cancelled or fails,
            // you can request to start the update again
            checkForUpdate()
        }
    }
}

override fun onResume() {
    super.onResume()

    appUpdateManager
        .appUpdateInfo
        .addOnSuccessListener { appUpdateInfo ->
            // If the update is downloaded but not installed,
            // notify the user to complete the update.
            if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
                showInstallSnackBar()
            }
        }
  }
}

To test:

  1. I uploaded to a test track (With the In-App Update code)
  2. I then downloaded that same app bundle above with the shareable link
  3. Then in my code, I increased the version code to a higher one than the one in step 1
  4. I then generated another signed bundle and uploaded to the-same internal test track.
  5. Now I copied the URL of the app in step 4 and visited...In there I saw "Update" -- Which means there is an update available. (I didnt click the Update on playstore)
  6. I closed PlayStore and opened my app...Thinking there would be an in app update dialog displayed, but nothing is showing... But on playstore, it reads 'Update'.

I have also cleared cache, and waited for hours but nothing.

I am also not getting the Toast message which I set "No update" yet when there is no update...Which shows that there is certainly an update...but the update dialog from Google not displaying.

Bullroarer answered 1/9, 2021 at 13:15 Comment(3)
same issue here. for me it actually worked once on one of my devices. on the other the dialog showed but the update failed with some error and I had to reboot the device in order to install it at all. after that I have been experiencing the same issue as youAntoine
I have same problem, did you found a fix?Reddick
same problem here. i followed the documentation but now working. any update?Espouse

© 2022 - 2024 — McMap. All rights reserved.