AssetPackManager

public interface AssetPackManager

com.google.android.play.core.assetpacks.AssetPackManager


Manages downloads of asset packs.

Summary

Public methods

abstract AssetPackStates cancel(List<String> packNames)

Requests to cancel the download of the specified asset packs.

abstract void clearListeners()

Unregisters all listeners previously added using registerListener(AssetPackStateUpdateListener).

abstract Task<AssetPackStates> fetch(List<String> packNames)

Requests to download the specified asset packs.

abstract AssetLocation getAssetLocation(String packName, String assetPath)

[advanced API] Returns the location of an asset in a pack, or null if the asset is not present in the given pack.

abstract AssetPackLocation getPackLocation(String packName)

Returns the location of the specified asset pack on the device or null if this pack is not downloaded.

abstract Map<StringAssetPackLocation> getPackLocations()

Returns the location of all installed asset packs as a mapping from the asset pack name to an AssetPackLocation.

abstract Task<AssetPackStates> getPackStates(List<String> packNames)

Requests download state or details for the specified asset packs.

abstract void registerListener(AssetPackStateUpdateListener listener)

Registers a listener that will be notified of changes to the state of pack downloads for this app.

abstract Task<Void> removePack(String packName)

Deletes the specified asset pack from the internal storage of the app.

abstract Task<Integer> showCellularDataConfirmation(Activity activity)

Shows a confirmation dialog to resume all pack downloads that are currently in the AssetPackStatus.WAITING_FOR_WIFI state.

abstract void unregisterListener(AssetPackStateUpdateListener listener)

Unregisters a listener previously added using registerListener(AssetPackStateUpdateListener).

Public methods

cancel

public abstract AssetPackStates cancel (List<String> packNames)

Requests to cancel the download of the specified asset packs.

Note: Only active downloads can be canceled.

Parameters
packNames List

Returns
AssetPackStates The new state for all specified packs.

clearListeners

public abstract void clearListeners ()

Unregisters all listeners previously added using registerListener(AssetPackStateUpdateListener).

fetch

public abstract Task<AssetPackStates> fetch (List<String> packNames)

Requests to download the specified asset packs.

This method will fail if the app is not in the foreground.

Parameters
packNames List

Returns
Task<AssetPackStates> the state of all specified pack names

getAssetLocation

public abstract AssetLocation getAssetLocation (String packName, 
                String assetPath)

[advanced API] Returns the location of an asset in a pack, or null if the asset is not present in the given pack.

You don't need to use this API for common use-cases: you can use the standard File API for accessing assets from asset packs that were extracted into the filesystem; and you can use Android's AssetManager API to access assets from packs that were installed as APKs.

This API is useful for game engines that don't use Asset Manager and for developers that want a unified method to access assets, independently from the delivery mode.

Parameters
packName String

assetPath String

Returns
AssetLocation

getPackLocation

public abstract AssetPackLocation getPackLocation (String packName)

Returns the location of the specified asset pack on the device or null if this pack is not downloaded.

The files found at this path should not be modified.

Parameters
packName String

Returns
AssetPackLocation

getPackLocations

public abstract Map<StringAssetPackLocation> getPackLocations ()

Returns the location of all installed asset packs as a mapping from the asset pack name to an AssetPackLocation.

The files found at these paths should not be modified.

Returns
Map<StringAssetPackLocation>

getPackStates

public abstract Task<AssetPackStates> getPackStates (List<String> packNames)

Requests download state or details for the specified asset packs.

Do not use this method to determine whether an asset pack is downloaded. Instead use getPackLocation(String).

Parameters
packNames List

Returns
Task<AssetPackStates>

registerListener

public abstract void registerListener (AssetPackStateUpdateListener listener)

Registers a listener that will be notified of changes to the state of pack downloads for this app. Listeners should be subsequently unregistered using unregisterListener(AssetPackStateUpdateListener).

Parameters
listener AssetPackStateUpdateListener

removePack

public abstract Task<Void> removePack (String packName)

Deletes the specified asset pack from the internal storage of the app.

Use this method to delete asset packs instead of deleting files manually. This ensures that the Asset Pack will not be re-downloaded during an app update.

If the asset pack is currently being downloaded or installed, this method does not cancel the process. For this case, use cancel(List) instead.

Parameters
packName String

Returns
Task<Void> A task that will be successful only if files were successfully deleted.

showCellularDataConfirmation

public abstract Task<Integer> showCellularDataConfirmation (Activity activity)

Shows a confirmation dialog to resume all pack downloads that are currently in the AssetPackStatus.WAITING_FOR_WIFI state. If the user accepts the dialog, packs are downloaded over cellular data.

The status of an asset pack is set to AssetPackStatus.WAITING_FOR_WIFI if the user is currently not on a Wi-Fi connection and the asset pack is large or the user has set their download preference in the Play Store to only download apps over Wi-Fi. By showing this dialog, your app can ask the user if they accept downloading the asset pack over cellular data instead of waiting for Wi-Fi.

Parameters
activity Activity: the activity on top of which the confirmation dialog is displayed. Use your current activity for this.

Returns
Task<Integer> A Task that completes once the dialog has been accepted, denied or closed. A successful task result contains one of the following values:

unregisterListener

public abstract void unregisterListener (AssetPackStateUpdateListener listener)

Unregisters a listener previously added using registerListener(AssetPackStateUpdateListener).

Parameters
listener AssetPackStateUpdateListener