This library aims to simplify Android In App Updates. You can force your users to update to latest app version with just a few lines of code.
Visit https://code.allaboutapps.at/articles/android-in-app-updates/ to get some detailed informations about this library
implementation 'at.allaboutapps.inappupdater:inappupdater:{latest_version}'
inAppUpdateManager = InAppUpdateManager(activity)
inAppUpdateStatusDisposable = inAppUpdateManager.observeInAppUpdateStatus()
.subscribe { currentStatus ->
if (currentStatus.isUpdatePending()) { //just start the update if there is one in progress
inAppUpdateManager.startUpdate()
}
updateUI(currentStatus) // update the ui when a new status arrives
}
There are two modes
Flexible (default) - User can use the app during update download, installation and restart needs to be triggered by user
Immediate - User will be blocked until download and installation is finished, restart is triggered automatically
inAppUpdateManager.startUpdate(updateType)
There are some reasons when an update is mandatory. For this case you can implement a provider interface to decide if an update is a forced update
class DemoForceUpdateProvider : ForceUpdateProvider {
override fun requestUpdateShouldBeImmediate(availableVersionCode: Int, doUpdate: () -> Unit) {
// place your logic here
// if a forced update is needed, just call doUpdate
doUpdate()
}
Just provide to the InAppUpdateManager a second, optional parameter
inAppUpdateManager = InAppUpdateManager(this, DemoForceUpdateProvider())
The force update activity screen provided by Google Play Core library can be closed through the back button. So we need to override onActivityResult to force the update again
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
inAppUpdateManager.onActivityResult(requestCode, resultCode)
super.onActivityResult(requestCode, resultCode, data)
}
In App Updates needs a newer version of the app available in Play Store.