Skip to main content

LiveUpdateManager

The LiveUpdateManager is used to manage instances of web apps used with Live Updates. It follows a Singleton Pattern to allow access from anywhere in the application. LiveUpdateManager can be used in situations where you want to manually sync a web app, check the status of an active sync, and get the file path of the latest web assets on the device.

Methods

getLastSync

static

Check when an app was last synced. If no appId is passed in, returns the oldest sync time from all registered apps.

Usage

val lastSync = LiveUpdateManager.getLastSync(context)

Parameters

NameOptionalTypeDescription
contextfalseContextAn Android context
appIdtrueStringThe ID of the app registered with Live Updates

Returns: Long

sync

static

Checks a single app with live updates to see if any new builds are available. If they are, attempt to download, unzip, and update the saved data to reference the latest build.

Usage

// Sync all apps
LiveUpdateManager.sync(context)

// Sync a specific app
LiveUpdateManager.sync(context, "appId")

// Sync all apps not in parallel and with a callback
LiveUpdateManager.sync(context, async = false, callback = object : SyncCallback {
override fun onAppComplete(liveUpdate: LiveUpdate, failStep: FailStep?) {
if(failStep != null) {
Log.e("LiveUpdate","CALLBACK: Sync failed at step ${failStep.name} for app ${liveUpdate.appId}!")
} else {
Log.d("LiveUpdate","CALLBACK: Sync success for app ${liveUpdate.appId}!")
}
}

override fun onSyncComplete() {
Log.d("LiveUpdate","CALLBACK: Sync finished!")
}
})

Parameters

NameOptionalTypeDescription
contextfalseContextAn Android context
appIdtrueStringThe ID of the app registered with Live Updates
appIdstrueArray of StringsAn array of app IDs of apps registered with Live Updates
asynctrueBooleanIf true, multiple apps registered with Live Updates will sync in paralell. If false, Live Update sync operations will run one app at a time. Default is true
callbacktrueSyncCallbackA callback to notify on each app sync complete and when entire sync is complete

cancelSync

static

Attempts to cancel a running sync job. If no app ID is provided it will attempt to cancel all running sync jobs.

Usage

// Cancel all syncing apps
LiveUpdateManager.cancelSync()

// Cancel a specific syncing app
LiveUpdateManager.cancelSync("appId")

Parameters

NameOptionalTypeDescription
contextfalseContextAn Android context
appIdtrueStringThe ID of the app registered with Live Updates

getLatestAppDirectory

static

Get the latest directory for the updated app resources, if available. If the app has not been updated through Live Updates, null will be returned.

Usage

LiveUpdateManager.getLatestAppDirectory(context, "appId")

Parameters

NameTypeDescription
contextContextAn Android context
appIdStringThe ID of the app registered with Live Updates

Returns: File?

initialize

static

Initializes the file directory and shared preferences used to save update data.

Usage

LiveUpdateManager.initialize(context)

Parameters

NameTypeDescription
contextContextAn Android context

reset

static

Clears the live updates directory and saved update data. Provided for maintenance/troubleshooting purposes.

Usage

// Reset all apps
LiveUpdateManager.reset(context)

// Reset but retain downloaded app files
LiveUpdateManager.reset(context, true)

Parameters

NameOptionalTypeDescription
contextfalseContextAn Android context
retainCachetrueBooleanIf true, will persist downloaded web asset files through reset. Default is false

addLiveUpdateInstance

static

Adds an app to the LiveUpdateManager.

Usage

val liveUpdateConfig = LiveUpdate("appId", "production")
LiveUpdateManager.addLiveUpdateInstance(context, liveUpdateConfig)

Parameters

NameTypeDescription
contextContextAn Android context
liveUpdateLiveUpdateAn instance of an app to register with Live Updates

cleanStaleVersions

static

Clean stale versions of an app updated with Live Updates. Stale versions are any app snapshot files built for previous versions of the app binary and not currently used by any app channel.

Usage

// Clean all stale app versions
LiveUpdateManager.cleanStaleVersions(context)

// Clean app versions for a specific app
LiveUpdateManager.cleanStaleVersions(context, "appId")

Parameters

NameTypeDescription
contextContextAn Android context
appIdStringThe ID of the app registered with Live Updates

cleanVersions

static

Clean up unused/old app versions. If an app ID is provided the clean up will be restricted to that app.

Usage

// Clean all app versions
LiveUpdateManager.cleanVersions(context)

// Clean app versions for a specific app
LiveUpdateManager.cleanVersions(context, "appId")

Parameters

NameOptionalTypeDescription
contextfalseContextAn Android context
appIdtrueStringThe ID of the app registered with Live Updates

checkForUpdate

static

Check for an update for an app. If optional callback is provided, will run async.

Usage

// Synchronous check call in coroutine
val checkScope = CoroutineScope(Dispatchers.IO)
checkScope.launch {
val response = LiveUpdateManager.checkForUpdate(context, "appId")
println(response.body.toString())
}

// Async check call
LiveUpdateManager.checkForUpdate(context, "appId", object : CheckCallback {
override fun onComplete(result: CheckResponse?) {
// Do something with the result
}
})

Parameters

NameOptionalTypeDescription
contextfalseContextAn Android context
appIdfalseStringThe ID of the app registered with Live Updates
callbacktrueCheckCallbackA callback to handle the response from the update check request

downloadUpdate

static

Download an update for an app. If optional callback is provided, will run async.

Usage

// Synchronous download call in coroutine
val checkScope = CoroutineScope(Dispatchers.IO)
checkScope.launch {
val response = LiveUpdateManager.downloadUpdate(context, "appId", "snapshotId")
// Do something with result
println(response.body.toString())
}

// Async download call
LiveUpdateManager.downloadUpdate(applicationContext, "appId", "snapshotId", object : DownloadCallback {
override fun onComplete(result: DownloadResponse?) {
// Do something with result
}
})

Parameters

NameOptionalTypeDescription
contextfalseContextAn Android context
appIdfalseStringThe ID of the app registered with Live Updates
snapshotIdfalseStringThe ID of an app snapshot to download
callbacktrueDownloadCallbackA callback to handle the response from the download request

extractUpdate

static

Extract an update for an app. If optional callback is provided, will run async.

Usage

// Synchronous extract call in coroutine
val checkScope = CoroutineScope(Dispatchers.IO)
checkScope.launch {
val response = LiveUpdateManager.extractUpdate("appId", zipFile)
println(response?.path)
}

// Async extract call
LiveUpdateManager.extractUpdate("appId", zipFile, object : ExtractCallback {
override fun onComplete(result: File?) {
println(response?.path)
}
})

Parameters

NameOptionalTypeDescription
appIdfalseStringThe ID of the app registered with Live Updates
zipFilefalseFileThe zip file of the app snapshot to extract
callbacktrueExtractCallbackA callback to handle the response from the extract request

applyUpdate

static

Apply a downloaded and extracted Live Update snapshot to the app as the latest path.

Usage

LiveUpdateManager.applyUpdate(context, "appId", "snapshotId", "buildId")

Parameters

NameTypeDescription
contextContextAn Android context
appIdStringThe ID of the app registered with Live Updates
snapshotIdStringThe ID of an app snapshot to apply
buildIdStringThe ID of the build to apply

getApps

static

Get the map of all registered apps using Live Updates.

Usage

val apps = LiveUpdateManager.getApps()

Returns: Map<String, LiveUpdate>