Skip to content

Instantly share code, notes, and snippets.

@gb103
Created January 2, 2021 04:20
Show Gist options
  • Save gb103/ed26e19ff750dc633dc1dc96a8abb067 to your computer and use it in GitHub Desktop.
Save gb103/ed26e19ff750dc633dc1dc96a8abb067 to your computer and use it in GitHub Desktop.
Handle error in the dynamic feature download
splitInstallManager
.startInstall(request)
.addOnFailureListener { exception ->
when ((exception as SplitInstallException).errorCode) {
SplitInstallErrorCode.NETWORK_ERROR -> {
// Display a message that requests the user to establish a
// network connection.
}
SplitInstallErrorCode.ACTIVE_SESSIONS_LIMIT_EXCEEDED -> checkForActiveDownloads()
...
}
}
fun checkForActiveDownloads() {
splitInstallManager
// Returns a SplitInstallSessionState object for each active session as a List.
.sessionStates
.addOnCompleteListener { task ->
if (task.isSuccessful) {
// Check for active sessions.
for (state in task.result) {
if (state.status() == SplitInstallSessionStatus.DOWNLOADING) {
// Cancel the request, or request a deferred installation.
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment