Created
January 6, 2018 17:50
-
-
Save ar-android/319dfef248ff8adb7ac246ef71dfd626 to your computer and use it in GitHub Desktop.
CheckUpdate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void checkUpdate() { | |
FirebaseRemoteConfig 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"); | |
int updatedVersion = Integer.parseInt(build_version); | |
if (updatedVersion > BuildConfig.VERSION_CODE) { | |
new AlertDialog.Builder(this) | |
.setTitle(R.string.alert_title) | |
.setMessage(R.string.plase_update_version) | |
.setCancelable(false) | |
.setNegativeButton("Skip", (dialogInterface, i) -> { | |
dialogInterface.dismiss(); | |
}) | |
.setPositiveButton("Ok", (dialog, which) -> { | |
openPlayStore(); | |
dialog.dismiss(); | |
}).show(); | |
} else { | |
Log.d("Response", "checkUpdate: false"); | |
} | |
}); | |
} | |
public void openPlayStore() { | |
final String appPackageName = this.getPackageName(); | |
try { | |
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); | |
} catch (android.content.ActivityNotFoundException anfe) { | |
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