Last active
November 15, 2019 07:39
-
-
Save savvisingh/4cd8c9e433fadc21f117145ecdb7ba71 to your computer and use it in GitHub Desktop.
This file contains 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
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