Skip to content

Instantly share code, notes, and snippets.

@deepanshu42
Created September 2, 2018 20:43
Show Gist options
  • Save deepanshu42/a0c5716a9542a4a43930e4eaaf1ce4cc to your computer and use it in GitHub Desktop.
Save deepanshu42/a0c5716a9542a4a43930e4eaaf1ce4cc to your computer and use it in GitHub Desktop.
Request an on demand module with callbacks
int mySessionId = 0;
// Creates a listener for request status updates.
SplitInstallStateUpdatedListener listener = state -> {
if (state.status() == SplitInstallSessionStatus.FAILED
&& state.errorCode() == SplitInstallErrorCode.SERVICE_DIES) {
// Retry the request.
return;
}
if (state.sessionId() == mySessionId) {
switch (state.status()) {
case SplitInstallSessionStatus.DOWNLOADING:
int totalBytes = state.totalBytesToDownload();
int progress = state.bytesDownloaded();
// Update progress bar.
break;
case SplitInstallSessionStatus.INSTALLED:
//Module is downloaded successfully
break;
}
}
};
// Registers the listener.
splitInstallManager.registerListener(listener);
splitInstallManager.startInstall(request)
.addOnSuccessListener(sessionId -> { mySessionId = sessionId; })
.addOnFailureListener(exception -> {
switch(((SplitInstallException) exception).getErrorCode()) {
case SplitInstallErrorCode.NETWORK_ERROR:
//Network Error
break;
case SplitInstallErrorCode.MODULE_UNAVAILABLE:
//Module Not Available
break;
...
});
// When your app no longer requires further updates, unregister the listener.
splitInstallManager.unregisterListener(listener);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment