Skip to content

Instantly share code, notes, and snippets.

@varundwarkani
Created March 11, 2020 17:18
Show Gist options
  • Save varundwarkani/3ae614ba62d595d1a38d3bb0370fcd6c to your computer and use it in GitHub Desktop.
Save varundwarkani/3ae614ba62d595d1a38d3bb0370fcd6c to your computer and use it in GitHub Desktop.
In-App Update Task
com.google.android.play.core.tasks.Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo appUpdateInfo) {
if (compulsory) {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// For a flexible update, use AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(IMMEDIATE)) {
// Request the update.
startInAppUpdate(appUpdateInfo, true);
}
} else {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// For a flexible update, use AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
// Request the update.
startInAppUpdate(appUpdateInfo, false);
}
}
}
});
appUpdateInfoTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
startNormalUpdate();
Utils.showSnackbar(findViewById(android.R.id.content), "Ex: " + e.getMessage(), 2);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment