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