Image for post
Image for post

Checking an update is available

val updateManager = AppUpdateManagerFactory.create(this)
updateManager.appUpdateInfo.addOnSuccessListener {
if (it.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
it.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
}
}
updateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.IMMEDIATE,
this,
REQUEST_CODE_UPDATE)
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent
) {
if (requestCode === REQUEST_CODE_UPDATE) {
if (requestCode != RESULT_OK) {

}
}
}

Immediate in-app updates

Image for post
Image for post
override fun onResume() {
super.onResume()
val updateManager = AppUpdateManagerFactory.create(this)
updateManager.appUpdateInfo
.addOnSuccessListener {
if (it.updateAvailability() ==
UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
updateManager.startUpdateFlowForResult(
it,
IMMEDIATE,
this,
REQUEST_CODE_UPDATE)
}
}
}
}

Flexible in-app updates

Image for post
Image for post
updateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.FLEXIBLE,
this,
REQUEST_CODE_UPDATE)
val listener = InstallStateUpdatedListener {
// Handle install state
}
val updateManager = AppUpdateManagerFactory.create(this)
updateManager.registerListener(listener)
...updateManager.unregisterListener(listener)
appUpdateManager.completeUpdate()
updateManager.appUpdateInfo
.addOnSuccessListener {appUpdateInfo ->
if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
updateManager.completeUpdate()
}
}

Google Developers Experts

Experts on various Google products talking tech.

Joe Birch

Written by

Joe Birch

Android Engineering Lead at Buffer, Google Developer Expert for Android & Flutter - Passionate about mobile development and learning. www.joebirch.co

Google Developers Experts

Experts on various Google products talking tech.

Joe Birch

Written by

Joe Birch

Android Engineering Lead at Buffer, Google Developer Expert for Android & Flutter - Passionate about mobile development and learning. www.joebirch.co

Google Developers Experts

Experts on various Google products talking tech.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store