Looking for a job as android developer located in vienna? Just contact us
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.
- Add a SigningConfig to build.gradle
- Set versionCode to 9000 // or any other high number
- Set a unique application id
- Generate APK / AAB
- Upload APK / AAB to your play store account
- Do not use App signing ( Google will resign your app, so you cannot test it with local installations)
- Release app to play store (app must be published and available)
- Set versionCode to a lower number
- Run app
- In-app updates are available only to user accounts that own the app. So, make sure the account you’re using has downloaded your app from Google Play at least once before using the account to test in-app updates.
- Make sure that the app that you are testing in-app updates with has the same application ID and is signed with the same signing key as the one available from Google Play.