Created
March 11, 2020 17:18
-
-
Save varundwarkani/3ae614ba62d595d1a38d3bb0370fcd6c to your computer and use it in GitHub Desktop.
In-App Update Task
This file contains 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
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