Last active
February 20, 2021 03:17
-
-
Save eristoddle/82a98438ab8d1fc734bccc095d7ae905 to your computer and use it in GitHub Desktop.
Android In-App Update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
// For a flexible update, use AppUpdateType.FLEXIBLE | |
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE) | |
) { | |
// Request the update. | |
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, | |
// Include a request code to later monitor this update request. | |
MY_REQUEST_CODE) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment