Skip to content

Instantly share code, notes, and snippets.

appUpdateManager
.appUpdateInfo
.addOnSuccessListener { appUpdateInfo ->
...
// If the update is downloaded but not installed,
// notify the user to complete the update.
if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
popupSnackbarForCompleteUpdate()
}
// Create a listener to track downloading state updates.
val listener = InstallStateUpdatedListener { state ->
// Update progress indicator, request user to approve app reload
if (state.installStatus() == InstallStatus.DOWNLOADED) {
// After the update is downloaded, show a notification
// and request user confirmation to restart the app.
popupSnackbarForCompleteUpdate()
}
}
appUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by getAppUpdateInfo()
appUpdateInfo,
AppUpdateType.FLEXIBLE, activity,
// Include a request code to later monitor this update request.
MY_REQUEST_CODE
)
fun onActivityResult(requestCode:Int, resultCode:Int, data:Intent) {
if (myRequestCode === MY_REQUEST_CODE){
if (myRequestCode !== RESULT_OK){
log("Update flow failed! Result code: " + resultCode)
// If the update is cancelled or fails,
// you can request to start the update again.
}
}
}
appUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.FLEXIBLE' for flexible updates.
AppUpdateType.IMMEDIATE,
// The current activity making the update request.
this,
// Creates instance of the manager.
val appUpdateManager = AppUpdateManagerFactory.create(context)
// Returns an intent object that you use to check for an update.
val appUpdateInfoTask = appUpdateManager.appUpdateInfo
// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE