tamtoum1987
tamtoum1987

Reputation: 2067

inapp update android application installed but i'm getting the same version

i decrement version build and name , so version build and version name are lower than the version on play store, i implement inapp version update of google , everything work fine, the download has complete so i add button to tell user restart application, and when he click it the install page is showen and application restart but when application start it's the same version like before , so the installation doesn't work :(

   private fun showInAppUpdate() {

    mAppUpdateManager = AppUpdateManagerFactory.create(activity);

    mAppUpdateManager.registerListener(installStateUpdatedListener);


    // Creates instance of the manager.
    appUpdateManager = AppUpdateManagerFactory.create(activity)

    // 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 ->
        val a = appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
        val b = appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)


        if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
            // For a flexible update, use AppUpdateType.IMMEDIATE
            && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
        ) {
            // To avoid crash when startUpdateFlowForResult is called two times (by accident)
            try {

                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.
                    activity,
                    // Include a request code to later monitor this update request.
                    INAPP_UPDATE_REQUEST_CODE)

            }
            catch (e : Exception){
                e.printStackTrace()
            }

        }
        else {
            Log.e("", "checkForAppUpdateAvailability: something else");
        }
    }
  }




 val installStateUpdatedListener = object : InstallStateUpdatedListener {
    override fun onStateUpdate(state: InstallState) {
        if (state.installStatus() == InstallStatus.DOWNLOADED) {
            popupSnackbarForCompleteUpdate()
        } else if (state.installStatus() == InstallStatus.INSTALLED) {
            mAppUpdateManager?.unregisterListener(this)

        } else {
            // Download or install in progress
        }
    }
}

  /* Displays the snackbar notification and call to action. */
  fun popupSnackbarForCompleteUpdate() {
     val snackBar =  Snackbar.make(
       activity!!.findViewById(R.id.home_root),
        HtmlCompat.fromHtml(this.resources.getString(R.string.inapp_downlaod_complete), 
   HtmlCompat.FROM_HTML_MODE_LEGACY),
        Snackbar.LENGTH_INDEFINITE
    )
    snackBar.setTextColor(Color.WHITE)
    snackBar
        .apply {
            setAction(activity!!.resources.getString(R.string.inapp_restart)) { 
  appUpdateManager.completeUpdate() }
              setActionTextColor(Color.GREEN)
            show()
        }
}




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


    if (requestCode == INAPP_UPDATE_REQUEST_CODE) {
        if (resultCode != AppCompatActivity.RESULT_OK) {

            mAppUpdateManager?.unregisterListener(installStateUpdatedListener)
        }
    }
}

why the application does not update with the version on play store ?

Thank you for your help

Upvotes: 1

Views: 728

Answers (1)

BlackHatSamurai
BlackHatSamurai

Reputation: 23503

Mostly what is happening is that you are launching your first app from your code, then trying to update that app from the store. Ultimately, those are going to be 2 different apps (since the one from your code is going to be a debug version and unsigned); therefore, you won't see the update. If you want to test this, you would need to sign the app and install it on your phone rather than just launch it from the code.

Upvotes: 2

Related Questions