2

I am just trying to implement in app update service provided by google play core library API.

After publishing the newer version of the app to the internal test track, I get the updated version of the app in play store

enter image description here

But, I am unable to see the 'Update' button on the same page

enter image description here

Also, App is disable to update as per the implementation of code. Please help me regarding this.

private AppUpdateManager appUpdateManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        appUpdateManager = AppUpdateManagerFactory.create(this);
        InAppUpdate.setImmediateUpdate(appUpdateManager, this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        InAppUpdate.setImmediateUpdateOnResume(appUpdateManager, this);
    }
}

and

public class InAppUpdate {

    public static int REQUEST_APP_UPDATE = 302;

    public static void setImmediateUpdate(AppUpdateManager appUpdateManager, Activity activity) {

        appUpdateManager
                .getAppUpdateInfo()
                .addOnSuccessListener(
                        appUpdateInfo -> {

                            // Checks that the platform will allow the specified type of update.
                            if ((appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE)
                                    && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                                // Request the update.
                                try {
                                    appUpdateManager.startUpdateFlowForResult(
                                            appUpdateInfo,
                                            AppUpdateType.IMMEDIATE,
                                            activity,
                                            REQUEST_APP_UPDATE);
                                } catch (IntentSender.SendIntentException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
    }

    public static void setImmediateUpdateOnResume(AppUpdateManager appUpdateManager, Activity activity) {

        appUpdateManager
                .getAppUpdateInfo()
                .addOnSuccessListener(
                        appUpdateInfo -> {

                            if (appUpdateInfo.updateAvailability()
                                    == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                                // If an in-app update is already running, resume the update.
                                try {
                                    appUpdateManager.startUpdateFlowForResult(
                                            appUpdateInfo,
                                            AppUpdateType.IMMEDIATE,
                                            activity,
                                            REQUEST_APP_UPDATE);
                                } catch (IntentSender.SendIntentException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
    }

    public static void setFlexibleUpdate(AppUpdateManager appUpdateManager, Activity activity) {

        InstallStateUpdatedListener installStateUpdatedListener = installState -> {
            if (installState.installStatus() == InstallStatus.DOWNLOADED) {
                Snackbar snackbar =
                        Snackbar.make(
                                activity.findViewById(android.R.id.content),
                                activity.getString(R.string.in_app_snack_bar_message),
                                Snackbar.LENGTH_INDEFINITE);
                //lambda operation used for below action
                snackbar.setAction(activity.getString(R.string.in_app_snack_bar_action_title), view ->
                        appUpdateManager.completeUpdate());
                snackbar.setActionTextColor(activity.getResources().getColor(R.color.in_app_snack_bar_text_color))
                ;
                snackbar.show();
            } else
                Log.e("UPDATE", "Not downloaded yet");
        };

        appUpdateManager
                .getAppUpdateInfo()
                .addOnSuccessListener(
                        appUpdateInfo -> {

                            // Checks that the platform will allow the specified type of update.
                            if ((appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE)
                                    && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
                                // Request the update.
                                try {
                                    appUpdateManager.startUpdateFlowForResult(
                                            appUpdateInfo,
                                            AppUpdateType.FLEXIBLE,
                                            activity,
                                            REQUEST_APP_UPDATE);
                                } catch (IntentSender.SendIntentException e) {
                                    e.printStackTrace();
                                }
                            }
                        });

        appUpdateManager.registerListener(installStateUpdatedListener);
    }

    public static void setFlexibleUpdateOnResume(AppUpdateManager appUpdateManager, Activity activity) {

        appUpdateManager
                .getAppUpdateInfo()
                .addOnSuccessListener(
                        appUpdateInfo -> {

                            if (appUpdateInfo.updateAvailability()
                                    == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                                // If an in-app update is already running, resume the update.
                                try {
                                    appUpdateManager.startUpdateFlowForResult(
                                            appUpdateInfo,
                                            AppUpdateType.FLEXIBLE,
                                            activity,
                                            REQUEST_APP_UPDATE);
                                } catch (IntentSender.SendIntentException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
    }
}
HoRn
  • 1,458
  • 5
  • 20
  • 25

1 Answers1

0

the issue is probably that you are working on an app that you installed over the USB cable and not from PlayStore. Install your app from playstore and then it will work. also mind that when using in-app update the caches of your app may prevent it from recognizing the newly uploaded update so restart your app a couple of times and if necesarry delete caches to force it to reload data from google play

quealegriamasalegre
  • 2,887
  • 1
  • 13
  • 35