SplitInstallManager

public interface SplitInstallManager

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


Manages sessions for requesting and installing split APKs for additional features or language resources.

To learn more, read Request an on demand module.

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 the languages that are currently installed.

abstract Set<String> getInstalledModules()

Returns the modules that are currently 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 for your app that is alerted of state changes for module install requests.

abstract boolean startConfirmationDialogForResult(SplitInstallSessionState sessionState, IntentSenderForResultStarter starter, int requestCode)

Starts the user confirmation dialog from the provided SplitInstallSessionState.

abstract boolean startConfirmationDialogForResult(SplitInstallSessionState sessionState, ActivityResultLauncher<IntentSenderRequest> activityResultLauncher)

Starts the user confirmation dialog from the provided SplitInstallSessionState.

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 request to download and install split APKs for additional features or language resources.

abstract void unregisterListener(SplitInstallStateUpdatedListener listener)

Unregisters a listener you previously registered using registerListener(SplitInstallStateUpdatedListener).

Public methods

cancelInstall

public abstract Task<Void> cancelInstall (int sessionId)

Starts a request to cancel a pending split install.

Cancelling requests are best-effort. You can monitor the request state to listening for the SplitInstallSessionStatus.CANCELED state.

Parameters
sessionId int: the sessionId of the request you would like to cancel

Returns
Task<Void>

deferredInstall

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

Defers installation of given moduleNames. When called, the Play Store tries to eventually install those modules in the background.

If your app requires immediate access to a module, request to install the module in the foreground.

To learn more, read Defer installation of on demand modules.

Parameters
moduleNames List: the names of the modules you want to install in the background

Returns
Task<Void>

deferredLanguageInstall

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

Defers installation of given languages. When called, the Play Store tries to eventually install those languages in the background.

To learn more, read Download additional language resources.

Parameters
languages List: the languages you want to install in the background

Returns
Task<Void>

deferredLanguageUninstall

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

Defers uninstallation of given languages. When called, the Play Store tries to eventually uninstall these languages from the app in the background.

To learn more, read Uninstall additional language resources.

Parameters
languages List: the languages you want to uninstall in the background

Returns
Task<Void>

deferredUninstall

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

Defers uninstallation of given moduleNames. When called, the Play Store tries to eventually remove those modules in the background.

These moduleNames will not be included when the app is updated, even if they are marked as available at install-time in the updated version of the app. For the app to regain access to the modules, the app must request to install the modules again, or make the module available at install-time under a new module name.

To learn more, read Uninstall modules.

Parameters
moduleNames List: the names of the modules you want to uninstall in the background

Returns
Task<Void>

getInstalledLanguages

public abstract Set<String> getInstalledLanguages ()

Returns the languages that are currently installed.

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

Returns an empty set if an error occurs.

For Instant Apps, this API is not supported and the return value is undefined.

Note: Languages are considered installed even when they are emulated by SplitCompat because they are accessible to the app.

Note: This method does NOT work if you are deploying your bundle onto your device from Android Studio via `Run...` or if you test it via Gradle's `assemble[Debug|Release|...]` or `install[Debug|Release|...]`. In such situation, this method always returns an empty list. The recommended way to test this method is by uploading your bundle to Internal App Sharing.

Returns
Set<String> the languages that are currently installed

getInstalledModules

public abstract Set<String> getInstalledModules ()

Returns the modules that are currently installed (excluding the base module).

To learn more, read Manage installed modules.

Note: Modules are considered installed even when they are emulated by SplitCompat because they are accessible to the app.

Returns
Set<String>

getSessionState

public abstract 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. Instead, please use getInstalledModules().

To learn more, read Monitor the request state.

Parameters
sessionId int: the Id for the session you want to status for

Returns
Task<SplitInstallSessionState>

getSessionStates

public abstract 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. Instead, please use getInstalledModules().

To learn more, read Monitor the request state.

Returns
Task<List<SplitInstallSessionState>>

registerListener

public abstract void registerListener (SplitInstallStateUpdatedListener listener)

Registers a listener for your app that is alerted of state changes for module install requests.

You should unregister the listener using unregisterListener(SplitInstallStateUpdatedListener) when the request is resolved. To learn more, read Monitor the request state.

Parameters
listener SplitInstallStateUpdatedListener: the SplitInstallStateUpdatedListener you want to register for your app

startConfirmationDialogForResult

public abstract boolean startConfirmationDialogForResult (SplitInstallSessionState sessionState, 
                IntentSenderForResultStarter starter, 
                int requestCode)

Starts the user confirmation dialog from the provided SplitInstallSessionState.

This method should be called if you are starting installation from a Component different from an Activity and you don't want to receive the onActivityResult call on the Activity.

For example, you can use it for androidx.fragment.app.Fragment:

startConfirmationDialogForResult(
   sessionState, fragment::startIntentSenderForResult, requestCode);
 

Similar to Activity.startActivityForResult(Intent, int), this method is run "for result". The result from the confirmation dialog's Activity can be handled by the onActivityResult of the object that would normally receive an activity result when the starter's startIntentSenderForResult is called. The result is tagged with the provided requestCode.

To learn more, read Obtain user confirmation.

Parameters
sessionState SplitInstallSessionState: a SplitInstallSessionState with status SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION

starter IntentSenderForResultStarter: the intent IntentSenderForResultStarter

requestCode int: the request code that will be used for ERROR(/Activity#onActivityResult)

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

startConfirmationDialogForResult

public abstract boolean startConfirmationDialogForResult (SplitInstallSessionState sessionState, 
                ActivityResultLauncher<IntentSenderRequest> activityResultLauncher)

Starts the user confirmation dialog from the provided SplitInstallSessionState.

This method uses the ActivityResultLauncher provided by Jetpack components to launch the confirmation dialog for result.

Parameters
sessionState SplitInstallSessionState: a SplitInstallSessionState with status SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION

activityResultLauncher ActivityResultLauncher: an ActivityResultLauncher to launch the confirmation dialog.

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

startConfirmationDialogForResult

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

Starts the user confirmation dialog from the provided SplitInstallSessionState.

When your app receives a SplitInstallSessionState with status SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION, use this method to obtain consent to download the split via a user confirmation dialog.

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

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

To learn more, read Obtain user confirmation.

Parameters
sessionState SplitInstallSessionState: a SplitInstallSessionState with status SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION

activity Activity: the Activity that will be used for ERROR(/Activity#onActivityResult)

requestCode int: the request code that will be used for ERROR(/Activity#onActivityResult)

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

public abstract Task<Integer> startInstall (SplitInstallRequest request)

Initiates a request to download and install split APKs for additional features or language resources.

To learn more, read Request an on demand module or Download additional language resources.

Parameters
request SplitInstallRequest: the SplitInstallRequest you built for the install request

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

public abstract void unregisterListener (SplitInstallStateUpdatedListener listener)

Unregisters a listener you previously registered using registerListener(SplitInstallStateUpdatedListener).

Parameters
listener SplitInstallStateUpdatedListener