Android In App Update not installing APK after downloading APK in immediate mode

Viewed 843

Application is using immediate mode to update the application. It starts downloading the APK but after downloading the APK, it never install. UI hangs with showing download progress 100%. There is no feedback in immediate mode that download has been completed.

How to achieve download, installation and restart of app automatically for immediate mode?

I am using following mode to start the update with immediate mode.

        try {
            appUpdateManager.startUpdateFlowForResult(
                    appUpdateInfo,
                    AppUpdateType.IMMEDIATE,
                    getActivity(),
                    REQUEST_CODE_FOR_APP_UPDATE);
        } catch (IntentSender.SendIntentException e) {
            appUpdateFailed();
        }
2 Answers

Try using onActivityResult() you can check the log status for what happened to your update and the status code of it. Or you can always use Flexible update instead of Immediate. For more information refer this link

If anyone is still facing this problem, adding a listener to the AppUpdateManager and restarting the activity programmatically solved it for me.

They promise that Immediate mode would handle the app restart here in app update support but they don't.

Immediate: A full-screen user experience that requires the user to update and restart the app in order to continue using the app. This UX is best for cases where an update is critical for continued use of the app. After a user accepts an immediate update, Google Play handles the update installation and app restart.

Here is an example,

InstallStateUpdatedListener installStateUpdatedListener = new
        InstallStateUpdatedListener() {
            @Override
            public void onStateUpdate(InstallState state) {
                if (state.installStatus() == InstallStatus.DOWNLOADED){
                    Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                    finish();
                } else if (state.installStatus() == InstallStatus.INSTALLED){
                    if (appUpdateManager != null){
                        appUpdateManager.unregisterListener(installStateUpdatedListener);
                    }

                }
            }
        };

This code simply monitors the update status, and after the download is completed, it creates a new base intent and finishes the current one. That way the "OnResume" is called.

Register this listener to the AppUpdateManager:

appUpdateManager.registerListener(installStateUpdatedListener);

P.S.: I am not good at answering SO questions, but happy to share my workaround.

Related