Skip to content

Instantly share code, notes, and snippets.

@ar-android
Created November 4, 2018 19:59
Show Gist options
  • Select an option

  • Save ar-android/5af898c2b90b8c5734c9c59a9e26f871 to your computer and use it in GitHub Desktop.

Select an option

Save ar-android/5af898c2b90b8c5734c9c59a9e26f871 to your computer and use it in GitHub Desktop.
Force update app using remote config
private void startingUp() {
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setDeveloperModeEnabled(BuildConfig.DEBUG)
.build();
mFirebaseRemoteConfig.setConfigSettings(configSettings);
long cacheExpiration = 3600;
if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
cacheExpiration = 0;
}
mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
mFirebaseRemoteConfig.activateFetched();
}
String build_version = mFirebaseRemoteConfig.getString("build_version");
build_version = build_version.trim();
int updatedVersion = !build_version.equals("") ? Integer.parseInt(build_version) : 0;
if (updatedVersion > BuildConfig.VERSION_CODE) {
new AlertDialog.Builder(this)
.setTitle(R.string.alert_title)
.setMessage(R.string.plase_update_version)
.setCancelable(false)
.setNegativeButton("Abaikan", (dialogInterface, i) -> {
dialogInterface.dismiss();
yourAction();
})
.setPositiveButton("Perbarui", (dialog, which) -> {
dialog.dismiss();
openPlayStore(SplashActivity.this);
}).show();
} else {
yourAction();
}
});
}
openPlayStore(SplashActivity.this);
public static void openPlayStore(Activity activity){
final String appPackageName = activity.getPackageName();
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment