Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

SplitInstallManager

public interface SplitInstallManager

com.google.android.play.core.splitinstall.SplitInstallManager


Manages sessions for installing dynamic splits.

Summary

Public methods

abstract Task<Void> cancelInstall(int sessionId)

Starts a request to cancel a pending split install.

abstract Task<Void> deferredInstall(List<String> moduleNames)

Defers installation of given moduleNames.

abstract Task<Void> deferredLanguageInstall(List<Locale> languages)

Defers installation of given languages.

abstract Task<Void> deferredLanguageUninstall(List<Locale> languages)

Defers uninstallation of given languages.

abstract Task<Void> deferredUninstall(List<String> moduleNames)

Defers uninstallation of given moduleNames.

abstract Set<String> getInstalledLanguages()

Returns which languages are installed.

abstract Set<String> getInstalledModules()

Returns which modules are installed (excluding the base module).

abstract Task<SplitInstallSessionState> getSessionState(int sessionId)

Returns the current state of a split install session.

abstract Task<List<SplitInstallSessionState>> getSessionStates()

Returns the state for all active sessions belonging to the app.

abstract void registerListener(SplitInstallStateUpdatedListener listener)

Registers a listener that will be alerted of state changes for install sessions for this app.

abstract boolean startConfirmationDialogForResult(SplitInstallSessionState sessionState, Activity activity, int requestCode)

Starts the user confirmation dialog from the provided SplitInstallSessionState.

abstract Task<Integer> startInstall(SplitInstallRequest request)

Initiates a split install request.

abstract void unregisterListener(SplitInstallStateUpdatedListener listener)

Unregisters a listener previously added using registerListener(SplitInstallStateUpdatedListener).

Public methods

cancelInstall

Task<Void> cancelInstall (int sessionId)

Starts a request to cancel a pending split install.

Cancellation requests are best-effort, and success may be observed by listening to status changes for eventual CANCELED state.

Parameters
sessionId int

Returns
Task<Void>

deferredInstall

Task<Void> deferredInstall (List<String> moduleNames)

Defers installation of given moduleNames. Once called, the Play Store will try to eventually install those modules in the background.

Parameters
moduleNames List

Returns
Task<Void>

deferredLanguageInstall

Task<Void> deferredLanguageInstall (List<Locale> languages)

Defers installation of given languages. Once called, the Play Store will try to eventually install those languages in the background.

Parameters
languages List

Returns
Task<Void>

deferredLanguageUninstall

Task<Void> deferredLanguageUninstall (List<Locale> languages)

Defers uninstallation of given languages. Once called, the Play Store may uninstall these languages from the app.

Parameters
languages List

Returns
Task<Void>

deferredUninstall

Task<Void> deferredUninstall (List<String> moduleNames)

Defers uninstallation of given moduleNames. Once called, the Play Store will try to eventually remove those modules in the background.

These moduleNames will not be included when the app is updated, even if they are marked install-time in the updated version of the app. To regain access, they must be installed through split install api (or made install-time under a new module name).

Parameters
moduleNames List

Returns
Task<Void>

getInstalledLanguages

Set<String> getInstalledLanguages ()

Returns which languages are installed.

The app's default language is not included in the returned set.

Returns an empty set if an error occurs.

This API is not supported and the return value is undefined for instant apps.

Note: languages are considered installed even when they are just emulated by SplitCompat, since they are equally accessible by the app.

Returns
Set<String>

getInstalledModules

Set<String> getInstalledModules ()

Returns which modules are installed (excluding the base module).

Note: modules are considered installed even when they are just emulated by SplitCompat, since they are equally accessible by the app.

Returns
Set<String>

getSessionState

Task<SplitInstallSessionState> getSessionState (int sessionId)

Returns the current state of a split install session.

You should not use the session state to determine whether a module is installed. For that, please use getInstalledModules().

To learn more, read Monitor the request state.

Parameters
sessionId int

Returns
Task<SplitInstallSessionState>

getSessionStates

Task<List<SplitInstallSessionState>> getSessionStates ()

Returns the state for all active sessions belonging to the app.

You should not use the session state to determine whether a module is installed. For that, please use getInstalledModules().

To learn more, read Monitor the request state.

Returns
Task<List<SplitInstallSessionState>>

registerListener

void registerListener (SplitInstallStateUpdatedListener listener)

Registers a listener that will be alerted of state changes for install sessions for this app. Listeners should be subsequently unregistered using unregisterListener(SplitInstallStateUpdatedListener).

Parameters
listener SplitInstallStateUpdatedListener

startConfirmationDialogForResult

boolean startConfirmationDialogForResult (SplitInstallSessionState sessionState, 
                Activity activity, 
                int requestCode)

Starts the user confirmation dialog from the provided SplitInstallSessionState.

Given a SplitInstallSessionState with status REQUIRES_USER_CONFIRMATION, this method is used to start the corresponding user confirmation dialog.

This method is run "for result" - analogous to startActivityForResult(Intent, int) - and the result from the dialog can be handled by the provided activity's ERROR(/Activity#onActivityResult) and will be tagged with the provided requestCode.

The dialog returns right after user confirmation, with one of the following values:

Parameters
sessionState SplitInstallSessionState

activity Activity

requestCode int

Returns
boolean whether the session state is a valid and the dialog has been started

Throws
IntentSender.SendIntentException if there is an error when starting the dialog for result

startInstall

Task<Integer> startInstall (SplitInstallRequest request)

Initiates a split install request.

Parameters
request SplitInstallRequest

Returns
Task<Integer> session id, which can be used to subsequently interact with the session after it is created. A session id of 0 indicates that the splits are already installed; in this case no session is generated.

unregisterListener

void unregisterListener (SplitInstallStateUpdatedListener listener)

Unregisters a listener previously added using registerListener(SplitInstallStateUpdatedListener).

Parameters
listener SplitInstallStateUpdatedListener