1

I am working with the android in-app-update API, but I am not getting the callback to InstallStatus.INSTALLED case. I do get the callback for InstallStatus.DOWNLOADED case. And also I am able to successfully update the app, but I want to execute some logic in InstallStatus.INSTALLED case. So how and when am I supposed to get callback to InstallStatus.INSTALLED case.

My InstallStateUpdatedListener

class AppInstallStateUpdatedListener implements InstallStateUpdatedListener {

        private AppUpdateManager appUpdateManager;
        private View anchorView;

        AppInstallStateUpdatedListener(AppUpdateManager appUpdateManager, View anchorView) {
            this.appUpdateManager = appUpdateManager;
            this.anchorView = anchorView;
        }

        @Override
        public void onStateUpdate(InstallState state) {
            if (state.installStatus() == InstallStatus.DOWNLOADED) {
                popupSnackbarForCompleteUpdate(anchorView);

                Toast.makeText(context,"Downloaded in app update", Toast.LENGTH_SHORT).show();
            } else if (state.installStatus() == InstallStatus.INSTALLED) {
                Toast.makeText(context,"Installed in app update", Toast.LENGTH_SHORT).show();
                if (appUpdateManager != null) {
                    appUpdateManager.unregisterListener(this);
                }
            } else {
                Log.i(InAppUpdateUtils.class.getSimpleName(), "InstallStateUpdatedListener: state: " + state.installStatus());
            }
        }
    }

This is how i am attaching the listener (I have a class "InAppUpdateUtils", inside its constructor I am initializing the appUpdateManager and attaching listener to it) Below is the constructor.

public InAppUpdateUtils(Activity activity, View anchorView) {
        appUpdateManager = AppUpdateManagerFactory.create(activity);
        if (listener == null) {
            listener = new AppInstallStateUpdatedListener(appUpdateManager, anchorView);
            appUpdateManager.registerListener(listener);
        }
    }

This is how i am initiating the install

private void popupSnackbarForCompleteUpdate(View anchorVIew) {
        Snackbar snackbar =
                Snackbar.make(
                        anchorVIew,
                        "We have downloaded an update",
                        Snackbar.LENGTH_INDEFINITE);
        snackbar.setAction("INSTALL", v -> {

            updateCompleteTask = appUpdateManager.completeUpdate();
            if (updateCompleteTask != null) {
                updateCompleteTask.addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void result) {

                        Toast.makeText(QuikrApplication.context, "Install Success", Toast.LENGTH_LONG).show();
                        Log.d("APP_UPDATE", "Update install success");
                    }
                });
                updateCompleteTask.addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(Exception e) {
                        Toast.makeText(context, "Install Failed", Toast.LENGTH_LONG).show();
                        Log.d("APP_UPDATE", "Update install failed " + e.toString());
                    }
                });
            }
        });
        TextView tv = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
        tv.setTextColor(Color.WHITE);
        snackbar.setActionTextColor(anchorVIew.getContext().getResources().getColor(R.color.green));
        snackbar.show();
    }
  • Same behavior here. I debugged my app and the last state I get just before it restarts is `InstallStatus.INSTALLING`. My guess is that when performing the update in the foreground, the app actually restarts before the installed event is fired. The behavior might be different when you initiate the installation from the background https://developer.android.com/guide/playcore/in-app-updates#install_flexible – Makibo May 28 '20 at 07:53

0 Answers0