0

Force update code is not implemented in the previous version So I add Force update code in the new version(Version Code 6) and uploaded testing version on play store. Now For testing, I create new release build of version code 5 and install it in my device. On Login Popup to update and cancel is showing but on clicking on the update button it is navigating to play store where there is an open button instead of an update although higher version is available. I search and try different methods mentioned on StackOverflow but none of them is working for me. Please help me out to fix this issue.

public class AppointActivity extends AppCompatActivity implements ForceUpdateChecker.OnUpdateNeededListener{
}


    private void redirectStore(String updateUrl) {
        final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(updateUrl));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @Override
    public void onUpdateNeeded( final String updateUrl) {

        AlertDialog dialog = new AlertDialog.Builder(this)//Alert dialog have implemetation have two options
                .setTitle("New version available")
                .setMessage("Please, update app to new version to continue searching.")
                .setPositiveButton("Update Now",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                redirectStore(updateUrl);
                            }
                        }).setNegativeButton("Later",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create();
        dialog.setCancelable(true);
        dialog.show();
    }


public class ForceUpdateChecker {


    private static final String TAG = ForceUpdateChecker.class.getSimpleName();

    public static final String KEY_UPDATE_REQUIRED = "force_update_required";
    public static final String KEY_CURRENT_VERSION = "force_update_current_version";
    public static final String KEY_UPDATE_URL = "force_update_store_url";

    private OnUpdateNeededListener onUpdateNeededListener;
    private Context context;

    public interface OnUpdateNeededListener {
        void onUpdateNeeded(String updateUrl);
    }

    public static Builder with(@NonNull Context context) {
        return new Builder(context);
    }

    public ForceUpdateChecker(@NonNull Context context,
                              OnUpdateNeededListener onUpdateNeededListener) {
        this.context = context;
        this.onUpdateNeededListener = onUpdateNeededListener;
    }

    public void check() {
        final FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.getInstance();

        if (remoteConfig.getBoolean(KEY_UPDATE_REQUIRED)) {
            String currentVersion = remoteConfig.getString(KEY_CURRENT_VERSION);
            String appVersion = getAppVersion(context);
            String updateUrl = remoteConfig.getString(KEY_UPDATE_URL);

            if (!TextUtils.equals(currentVersion, appVersion)
                    && onUpdateNeededListener != null) {
                onUpdateNeededListener.onUpdateNeeded(updateUrl);
            }
        }
    }

    private String getAppVersion(Context context) {
        String result = "";

        try {
            result = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0)
                    .versionName;
            result = result.replaceAll("[a-zA-Z]|-", "");
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, e.getMessage());
            errorClass.logError(e);
        }
        return result;
    }

    public static class Builder {

        private Context context;
        private OnUpdateNeededListener onUpdateNeededListener;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder onUpdateNeeded(OnUpdateNeededListener onUpdateNeededListener) {
            this.onUpdateNeededListener = onUpdateNeededListener;
            return this;
        }

        public ForceUpdateChecker build() {
            return new ForceUpdateChecker(context, onUpdateNeededListener);
        }

        public ForceUpdateChecker check() {
            ForceUpdateChecker forceUpdateChecker = build();
            forceUpdateChecker.check();

            return forceUpdateChecker;
        }
    }

}

Thank you

Mahendra Gohil
  • 380
  • 1
  • 3
  • 21
  • Does this answer your question? [Google Play Store showing Open button instead of Update button](https://stackoverflow.com/questions/32086791/google-play-store-showing-open-button-instead-of-update-button) – greeble31 Jan 28 '20 at 16:01
  • have you try to clear cache memory of your app and play store ? – Mahendra Gohil Jan 30 '20 at 05:47

3 Answers3

1

If you have installed your application through adb or installed from other sources, Google play will show "Open" instead of "Update".

If your app have been installed through Google Play or it should be installed through a system application to show an update in Google Play,

Mahendra Gohil
  • 380
  • 1
  • 3
  • 21
0

This is issue of play store.I have also face same issue.If you go back and again go to same app it will be show update button instead of open.

Off-topic : Why you are not use InAppUpdate instead of your code? For InAppUpdate please prefer below link of my answer

https://stackoverflow.com/a/59930031/11158194

I hope this can help you!

Thank You.

Hardik Talaviya
  • 1,396
  • 5
  • 18
  • I also tried InAppUpdate ... in that case, also open button is showing instead of update option appUpdateInfo.updateAvailability() return 1 which means Update not available although play store have higher version of my app. – Priya Kumari Jan 29 '20 at 08:46
  • This is issue of play store as said in my answer.If you go back and again go to same app it will be show update button instead of open. – Hardik Talaviya Jan 29 '20 at 09:45
-1

Check your version name and version code in build.gradle file of app level You can check this link "https://github.com/hummatli/AndroidAppUpdater"

Ash
  • 17
  • 4