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
- Kotlin
- Java
val lastSync = LiveUpdateManager.getLastSync(context)
Long lastSync = LiveUpdateManager.getLastSync(context);
Parameters
Name | Optional | Type | Description |
---|---|---|---|
context | false | Context | An Android context |
appId | true | String | The 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
- Kotlin
- Java
// 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!")
}
})
// Sync all apps
LiveUpdateManager.sync(context);
// Sync a specific app
LiveUpdateManager.sync(context, "appId");
// Sync specific apps with a callback
LiveUpdateManager.sync(context, new String[] {"appId1", "appId2"} ,true, new SyncCallback() {
@Override
public void onAppComplete(LiveUpdate liveUpdate, FailStep failStep) {
if (failStep != null) {
Log.d("LiveUpdates", "App " + liveUpdate.getAppId() + " failed syncing at step " + failStep.name());
} else {
Log.d("LiveUpdates", "App " + liveUpdate.getAppId() + " finished syncing");
}
}
@Override
public void onSyncComplete() {
settingsViewModel.setResetProfile(true);
}
});
Parameters
Name | Optional | Type | Description |
---|---|---|---|
context | false | Context | An Android context |
appId | true | String | The ID of the app registered with Live Updates |
appIds | true | Array of Strings | An array of app IDs of apps registered with Live Updates |
async | true | Boolean | If 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 |
callback | true | SyncCallback | A 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
- Kotlin
- Java
// Cancel all syncing apps
LiveUpdateManager.cancelSync()
// Cancel a specific syncing app
LiveUpdateManager.cancelSync("appId")
// Cancel all syncing apps
LiveUpdateManager.cancelSync();
// Cancel a specific syncing app
LiveUpdateManager.cancelSync("appId");
Parameters
Name | Optional | Type | Description |
---|---|---|---|
context | false | Context | An Android context |
appId | true | String | The 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
- Kotlin
- Java
LiveUpdateManager.getLatestAppDirectory(context, "appId")
LiveUpdateManager.getLatestAppDirectory(context, "appId");
Parameters
Name | Type | Description |
---|---|---|
context | Context | An Android context |
appId | String | The 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
- Kotlin
- Java
LiveUpdateManager.initialize(context)
LiveUpdateManager.initialize(context);
Parameters
Name | Type | Description |
---|---|---|
context | Context | An Android context |
reset
static
Clears the live updates directory and saved update data. Provided for maintenance/troubleshooting purposes.
Usage
- Kotlin
- Java
// Reset all apps
LiveUpdateManager.reset(context)
// Reset but retain downloaded app files
LiveUpdateManager.reset(context, true)
// Reset all apps
LiveUpdateManager.reset(context);
// Reset but retain downloaded app files
LiveUpdateManager.reset(context, true);
Parameters
Name | Optional | Type | Description |
---|---|---|---|
context | false | Context | An Android context |
retainCache | true | Boolean | If true, will persist downloaded web asset files through reset. Default is false |
addLiveUpdateInstance
static
Adds an app to the LiveUpdateManager.
Usage
- Kotlin
- Java
val liveUpdateConfig = LiveUpdate("appId", "production")
LiveUpdateManager.addLiveUpdateInstance(context, liveUpdateConfig)
LiveUpdate liveUpdateConfig = new LiveUpdate("appId", "production");
LiveUpdateManager.addLiveUpdateInstance(context, liveUpdateConfig);
Parameters
Name | Type | Description |
---|---|---|
context | Context | An Android context |
liveUpdate | LiveUpdate | An 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
- Kotlin
- Java
// Clean all stale app versions
LiveUpdateManager.cleanStaleVersions(context)
// Clean app versions for a specific app
LiveUpdateManager.cleanStaleVersions(context, "appId")
// Clean all stale app versions
LiveUpdateManager.cleanStaleVersions(context);
// Clean app versions for a specific app
LiveUpdateManager.cleanStaleVersions(context, "appId");
Parameters
Name | Type | Description |
---|---|---|
context | Context | An Android context |
appId | String | The 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
- Kotlin
- Java
// Clean all app versions
LiveUpdateManager.cleanVersions(context)
// Clean app versions for a specific app
LiveUpdateManager.cleanVersions(context, "appId")
// Clean all app versions
LiveUpdateManager.cleanVersions(context);
// Clean app versions for a specific app
LiveUpdateManager.cleanVersions(context, "appId");
Parameters
Name | Optional | Type | Description |
---|---|---|---|
context | false | Context | An Android context |
appId | true | String | The 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
- Kotlin
- Java
// 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
}
})
// Synchronous check call in an executor
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
CheckResponse response = LiveUpdateManager.checkForUpdate(getContext(), "appId");
// Do something with response
});
// Async check call
LiveUpdateManager.checkForUpdate(context, "appId", checkResponse -> {
// Do something with response
});
Parameters
Name | Optional | Type | Description |
---|---|---|---|
context | false | Context | An Android context |
appId | false | String | The ID of the app registered with Live Updates |
callback | true | CheckCallback | A 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
- Kotlin
- Java
// 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
}
})
// Synchronous download call in an executor
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
DownloadResponse response = LiveUpdateManager.downloadUpdate(getContext(), "appId", "snapshotId");
});
// Async download call
LiveUpdateManager.downloadUpdate(getContext(), "appId", "snapshotId", downloadResponse -> {
// Do something with response
});
Parameters
Name | Optional | Type | Description |
---|---|---|---|
context | false | Context | An Android context |
appId | false | String | The ID of the app registered with Live Updates |
snapshotId | false | String | The ID of an app snapshot to download |
callback | true | DownloadCallback | A 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
- Kotlin
- Java
// 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)
}
})
// Synchronous extract call in an extractor
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
File extractedFile = LiveUpdateManager.extractUpdate(getContext(), zipFile);
});
// Async extract call
LiveUpdateManager.extractUpdate(getContext(), zipFile, extractedFile -> {
// Do something with file
});
Parameters
Name | Optional | Type | Description |
---|---|---|---|
appId | false | String | The ID of the app registered with Live Updates |
zipFile | false | File | The zip file of the app snapshot to extract |
callback | true | ExtractCallback | A 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
- Kotlin
- Java
LiveUpdateManager.applyUpdate(context, "appId", "snapshotId", "buildId")
LiveUpdateManager.applyUpdate(context, "appId", "snapshotId", "buildId");
Parameters
Name | Type | Description |
---|---|---|
context | Context | An Android context |
appId | String | The ID of the app registered with Live Updates |
snapshotId | String | The ID of an app snapshot to apply |
buildId | String | The ID of the build to apply |
getApps
static
Get the map of all registered apps using Live Updates.
Usage
- Kotlin
- Java
val apps = LiveUpdateManager.getApps()
Map<String, LiveUpdate> apps = LiveUpdateManager.getApps();
Returns: Map<String, LiveUpdate>