Skip to content

Instantly share code, notes, and snippets.

@savvisingh
Last active November 15, 2019 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save savvisingh/4cd8c9e433fadc21f117145ecdb7ba71 to your computer and use it in GitHub Desktop.
Save savvisingh/4cd8c9e433fadc21f117145ecdb7ba71 to your computer and use it in GitHub Desktop.
var mySessionId = 0;
// Creates a listener for request status updates.
var listener = SplitInstallStateUpdatedListener{
if(it.sessionId() == sessionId){
when(it.status()){
SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> {
splitInstallManager.startConfirmationDialogForResult(it, activity, HomeActivity.REQUEST_USER_CONFIRMATIOON)
}
SplitInstallSessionStatus.INSTALLED -> {
//Module is downloaded successfully
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
SplitInstallHelper.updateAppInfo(context.applicationContext)
}
}
SplitInstallSessionStatus.FAILED,
SplitInstallSessionStatus.CANCELED,
SplitInstallSessionStatus.CANCELING -> {
sessionId = null
// Retry
}
SplitInstallSessionStatus.DOWNLOADING -> {
val totalBytes = it.totalBytesToDownload()
val progress = it.bytesDownloaded()
// Update progress bar.
}
}
}
}
// Registers the listener.
splitInstallManager.registerListener(listener)
splitInstallManager.startInstall(request)
.addOnSuccessListener { mySessionId = it }
.addOnFailureListener {
Logger.logException(TAG, it)
when(it){
is SplitInstallException -> {
when ((it).errorCode) {
SplitInstallErrorCode.NETWORK_ERROR -> {
// Display a message that requests the user to establish a
// network connection.
}
SplitInstallErrorCode.ACTIVE_SESSIONS_LIMIT_EXCEEDED -> {
checkForActiveDownloads()
}
}
}
}
}
// 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