Created
September 2, 2018 20:43
-
-
Save deepanshu42/a0c5716a9542a4a43930e4eaaf1ce4cc to your computer and use it in GitHub Desktop.
Request an on demand module with callbacks
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
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