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

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

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.