в обновлении приложения не устанавливается последняя версия apk - PullRequest
0 голосов
/ 01 ноября 2019

Я успешно завершил обновление диалога загрузки и загрузил обновление, позвонив по номеру appUpdateManager.completeInstall(), но после этого он перезапустит приложение, и я не получу обновление моего приложения. мое приложение хранит старую версию, а в диспетчере обновлений приложения снова и снова и снова показывает show diaog. что не так ? для информации. Я использую пакетный файл в моей консоли Google Play и генерирую asign .apk с тем же тестом хранилища ключей для обновления приложения. подскажите пожалуйста что не так.

 private fun checkForAppUpdate() {
        // Creates instance of the manager.
        appUpdateManager = AppUpdateManagerFactory.create(this)

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

        // Create a listener to track request state updates.
        installStateUpdatedListener = InstallStateUpdatedListener { installState ->
                // Show module progress, log state, or install the update.
                if (installState.installStatus() == InstallStatus.DOWNLOADED) {
                    // After the update is downloaded, show a notification
                    // and request user confirmation to restart the app.
                    popupSnackbarForCompleteUpdateAndUnregister()
                }
            //you cannot move from this activity cause listener at this activity

            }

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

        // Checks that the platform will allow the specified type of update.
        appUpdateInfoTask?.addOnSuccessListener { appUpdateInfo ->
            this.updateInfo = appUpdateInfo
            if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
                // Request the update.
                if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {

                    // Start an update.
                    startAppUpdateFlexible(appUpdateInfo)


                } else if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {

                    // Start an update.
                    startAppUpdateImmediate(appUpdateInfo)
                }else{
                    //no update
                    runningSplashTime()
                }
            }
        }

        appUpdateInfoTask?.addOnFailureListener {
            //runnig splash if have no update or failure
            runningSplashTime()
        }
    }
 private fun startAppUpdateImmediate(appUpdateInfo: AppUpdateInfo) {
        try {
            longToast("start update IMMEDIATE")
            appUpdateManager?.startUpdateFlowForResult(
                appUpdateInfo,
                AppUpdateType.IMMEDIATE,
                // The current activity making the update request.
                this,
                // Include a request code to later monitor this update request.
                REQ_CODE_VERSION_UPDATE_IMMEDIATE
            )
        } catch (e: IntentSender.SendIntentException) {
            e.printStackTrace()
            unregisterInstallStateUpdListener()
        }

    }
private fun startAppUpdateFlexible(appUpdateInfo: AppUpdateInfo) {
        try {
            longToast("start update Flexible")

            appUpdateManager?.startUpdateFlowForResult(
                appUpdateInfo,
                AppUpdateType.FLEXIBLE,
                // The current activity making the update request.
                this,
                // Include a request code to later monitor this update request.
                REQ_CODE_VERSION_UPDATE_FLEKSIBEL
            )
        } catch (e: IntentSender.SendIntentException) {
            e.printStackTrace()
            unregisterInstallStateUpdListener()
        }

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

            REQ_CODE_VERSION_UPDATE_FLEKSIBEL -> if (resultCode !== Activity.RESULT_OK) { //RESULT_OK / RESULT_CANCELED / RESULT_IN_APP_UPDATE_FAILED
                Timber.d("Update flow failed! Result code: $resultCode")
                // If the update is cancelled or fails,
                // you can request to start the update again.
                unregisterInstallStateUpdListener()
                //user not wanna update
                runningSplashTime()
            }
            REQ_CODE_VERSION_UPDATE_IMMEDIATE -> if (resultCode !== Activity.RESULT_OK) { //RESULT_OK / RESULT_CANCELED / RESULT_IN_APP_UPDATE_FAILED
                Timber.d("Update flow failed! Result code: $resultCode")
                // If the update is cancelled or fails,
                // you can request to start the update again.
                unregisterInstallStateUpdListener()
                //user must update
                popUpUserMustbeUpdate()

            }
        }
    }
private fun popupSnackbarForCompleteUpdateAndUnregister() {
        Snackbar.make(imageView
            ,
            "An update has just been downloaded.",
            Snackbar.LENGTH_LONG
        ).apply {
            setAction("RESTART") {
                appUpdateManager?.completeUpdate()
                unregisterInstallStateUpdListener()
            }
            setActionTextColor(resources.getColor(R.color.colorPrimary))
            show()
        }

        //appUpdateManager?.completeUpdate()

    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...