Google is committed to advancing racial equity for Black communities. See how.

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 or is outdated.

abstract Map<String, AssetPackLocation> 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 WAITING_FOR_WIFI state.

abstract void unregisterListener(AssetPackStateUpdateListener listener)

Unregisters a listener previously added using registerListener(AssetPackStateUpdateListener).

Public methods

cancel

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

void clearListeners ()

Unregisters all listeners previously added using registerListener(AssetPackStateUpdateListener).

fetch

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

Requests to download the specified asset packs.

Parameters
packNames List

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

getAssetLocation

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

AssetPackLocation getPackLocation (String packName)

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

The files found at this path should not be modified.

Parameters
packName String

Returns
AssetPackLocation

getPackLocations

Map<String, AssetPackLocation> 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<String, AssetPackLocation>

getPackStates

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

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

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

Task<Integer> showCellularDataConfirmation (Activity activity)

Shows a confirmation dialog to resume all pack downloads that are currently in the 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 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:
  • RESULT_OK if the user accepted.
  • RESULT_CANCELED if the user denied or the dialog has been closed in any other way (e.g. backpress).

unregisterListener

void unregisterListener (AssetPackStateUpdateListener listener)

Unregisters a listener previously added using registerListener(AssetPackStateUpdateListener).

Parameters
listener AssetPackStateUpdateListener