# AiPackManager

# AiPackManager


`
public


interface
AiPackManager
`


`


`

|----------------------------------------------------|
| com.google.android.play.core.aipacks.AiPackManager |

<br />

*** ** * ** ***

Manages downloads of AI packs.

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[AiPackStates](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackStates.html)                                                                                                                                                       | ` `[cancel](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#cancel(java.util.List<java.lang.String>))`(`[List](https://developer.android.com/reference/java/util/List.html)`<`[String](https://developer.android.com/reference/java/lang/String.html)`> packNames) ` Requests to cancel the download of the specified AI packs.                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` abstract void`                                                                                                                                                                                                                                                                 | ` `[clearListeners](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#clearListeners())`() ` Unregisters all listeners previously added using [registerListener(AiPackStateUpdateListener)](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#registerListener(com.google.android.play.core.aipacks.AiPackStateUpdateListener)).                                                                                                                                                                                                                                                                                                                                                     |
| ` abstract `[Task](https://developer.google.com/android/reference/com/google/android/gms/tasks/Task.html)`<`[AiPackStates](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackStates.html)`>`                                                    | ` `[fetch](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#fetch(java.util.List<java.lang.String>))`(`[List](https://developer.android.com/reference/java/util/List.html)`<`[String](https://developer.android.com/reference/java/lang/String.html)`> packNames) ` Requests to download the specified AI packs.                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` abstract `[AiAssetLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiAssetLocation.html)                                                                                                                                                 | ` `[getAiAssetLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#getAiAssetLocation(java.lang.String,%20java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` packName, `[String](https://developer.android.com/reference/java/lang/String.html)` assetPath) ` \[advanced API\] Returns the location of an AI asset in a pack, or `null` if the AI asset is not present in the given pack.                                                                                                                                                                                                                                                                                        |
| ` abstract `[AiPackLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackLocation.html)                                                                                                                                                   | ` `[getPackLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#getPackLocation(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` packName) ` Returns the location of the specified AI pack on the device or `null` if this pack is not downloaded.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` abstract `[Map](https://developer.android.com/reference/java/util/Map.html)`<`[String](https://developer.android.com/reference/java/lang/String.html)`, `[AiPackLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackLocation.html)`>` | ` `[getPackLocations](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#getPackLocations())`() ` Returns the location of all installed AI packs as a mapping from the AI pack name to an [AiPackLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackLocation.html).                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` abstract `[Task](https://developer.google.com/android/reference/com/google/android/gms/tasks/Task.html)`<`[AiPackStates](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackStates.html)`>`                                                    | ` `[getPackStates](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#getPackStates(java.util.List<java.lang.String>))`(`[List](https://developer.android.com/reference/java/util/List.html)`<`[String](https://developer.android.com/reference/java/lang/String.html)`> packNames) ` Requests download state or details for the specified AI packs.                                                                                                                                                                                                                                                                                                                                                                                |
| ` abstract void`                                                                                                                                                                                                                                                                 | ` `[registerListener](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#registerListener(com.google.android.play.core.aipacks.AiPackStateUpdateListener))`(`[AiPackStateUpdateListener](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackStateUpdateListener.html)` listener) ` Registers a listener that will be notified of changes to the state of pack downloads for this app.                                                                                                                                                                                                                                                                                                               |
| ` abstract `[Task](https://developer.google.com/android/reference/com/google/android/gms/tasks/Task.html)`<`[Void](https://developer.android.com/reference/java/lang/Void.html)`>`                                                                                               | ` `[removePack](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#removePack(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` packName) ` Deletes the specified AI pack from the internal storage of the app.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` abstract boolean`                                                                                                                                                                                                                                                              | ` `[showConfirmationDialog](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#showConfirmationDialog(androidx.activity.result.ActivityResultLauncher<androidx.activity.result.IntentSenderRequest>))`(ActivityResultLauncher<IntentSenderRequest> activityResultLauncher) ` Shows a dialog that asks the user for consent to download packs that are currently in either the [AiPackStatus.REQUIRES_USER_CONFIRMATION](https://developer.android.com/reference/com/google/android/play/core/aipacks/model/AiPackStatus.html#REQUIRES_USER_CONFIRMATION) state or the [AiPackStatus.WAITING_FOR_WIFI](https://developer.android.com/reference/com/google/android/play/core/aipacks/model/AiPackStatus.html#WAITING_FOR_WIFI) state. |
| ` abstract void`                                                                                                                                                                                                                                                                 | ` `[unregisterListener](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#unregisterListener(com.google.android.play.core.aipacks.AiPackStateUpdateListener))`(`[AiPackStateUpdateListener](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackStateUpdateListener.html)` listener) ` Unregisters a listener previously added using [registerListener(AiPackStateUpdateListener)](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#registerListener(com.google.android.play.core.aipacks.AiPackStateUpdateListener)).                                                                                                                               |

## Public methods

### cancel

```
public abstract AiPackStates cancel (List<String> packNames)
```

Requests to cancel the download of the specified AI packs.

Note: Only active downloads can be canceled.

<br />

|         Parameters         ||
|-------------|---------------|
| `packNames` | `List` <br /> |

|                                                                            Returns                                                                            ||
|----------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [AiPackStates](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackStates.html) | The new state for all specified packs. <br /> |

### clearListeners

```
public abstract void clearListeners ()
```

Unregisters all listeners previously added using [registerListener(AiPackStateUpdateListener)](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#registerListener(com.google.android.play.core.aipacks.AiPackStateUpdateListener)).

<br />

### fetch

```
public abstract Task<AiPackStates> fetch (List<String> packNames)
```

Requests to download the specified AI packs.

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

<br />

|         Parameters         ||
|-------------|---------------|
| `packNames` | `List` <br /> |

|                                                                                                                             Returns                                                                                                                             ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [Task](https://developer.google.com/android/reference/com/google/android/gms/tasks/Task.html)`<`[AiPackStates](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackStates.html)`>` | the state of all specified pack names <br /> |

### getAiAssetLocation

```
public abstract AiAssetLocation getAiAssetLocation (String packName, 
                String assetPath)
```

\[advanced API\] Returns the location of an AI asset in a pack, or `null` if the AI 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 AI assets from packs that were extracted into the filesystem; and you can use
Android's AssetManager API to access AI 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 AI assets, independently from the delivery mode.

<br />

|          Parameters          ||
|-------------|-----------------|
| `packName`  | `String` <br /> |
| `assetPath` | `String` <br /> |

|                                                           Returns                                                            ||
|----------------------------------------------------------------------------------------------------------------------|--------|
| [AiAssetLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiAssetLocation.html) | <br /> |

### getPackLocation

```
public abstract AiPackLocation getPackLocation (String packName)
```

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

The files found at this path should not be modified.

<br />

|         Parameters          ||
|------------|-----------------|
| `packName` | `String` <br /> |

|                                                          Returns                                                           ||
|--------------------------------------------------------------------------------------------------------------------|--------|
| [AiPackLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackLocation.html) | <br /> |

### getPackLocations

```
public abstract Map<String, AiPackLocation> getPackLocations ()
```

Returns the location of all installed AI packs as a mapping from the AI pack name to an [AiPackLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackLocation.html).

The files found at these paths should not be modified.

<br />

|                                                                                                                                   Returns                                                                                                                                    ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|
| [Map](https://developer.android.com/reference/java/util/Map.html)`<`[String](https://developer.android.com/reference/java/lang/String.html)`, `[AiPackLocation](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackLocation.html)`>` | <br /> |

### getPackStates

```
public abstract Task<AiPackStates> getPackStates (List<String> packNames)
```

Requests download state or details for the specified AI packs.

Do not use this method to determine whether an AI pack is downloaded. Instead use [getPackLocation(String)](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#getPackLocation(java.lang.String)).

<br />

|         Parameters         ||
|-------------|---------------|
| `packNames` | `List` <br /> |

|                                                                                                          Returns                                                                                                          ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|
| [Task](https://developer.google.com/android/reference/com/google/android/gms/tasks/Task.html)`<`[AiPackStates](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackStates.html)`>` | <br /> |

### registerListener

```
public abstract void registerListener (AiPackStateUpdateListener 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(AiPackStateUpdateListener)](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#unregisterListener(com.google.android.play.core.aipacks.AiPackStateUpdateListener)).

<br />

|                   Parameters                   ||
|------------|------------------------------------|
| `listener` | `AiPackStateUpdateListener` <br /> |

### removePack

```
public abstract Task<Void> removePack (String packName)
```

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

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

If the AI pack is currently being downloaded or installed, this method does not cancel the
process. For this case, use [cancel(List)](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#cancel(java.util.List<java.lang.String>)) instead.

<br />

|         Parameters          ||
|------------|-----------------|
| `packName` | `String` <br /> |

|                                                                                                                        Returns                                                                                                                         ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| [Task](https://developer.google.com/android/reference/com/google/android/gms/tasks/Task.html)`<`[Void](https://developer.android.com/reference/java/lang/Void.html)`>` | A task that will be successful only if files were successfully deleted. <br /> |

### showConfirmationDialog

```
public abstract boolean showConfirmationDialog (ActivityResultLauncher<IntentSenderRequest> activityResultLauncher)
```

Shows a dialog that asks the user for consent to download packs that are currently in either
the [AiPackStatus.REQUIRES_USER_CONFIRMATION](https://developer.android.com/reference/com/google/android/play/core/aipacks/model/AiPackStatus.html#REQUIRES_USER_CONFIRMATION)
state or the [AiPackStatus.WAITING_FOR_WIFI](https://developer.android.com/reference/com/google/android/play/core/aipacks/model/AiPackStatus.html#WAITING_FOR_WIFI)
state.

If the app has not been installed by Play, an update may be triggered to ensure that a valid
version is installed. This will cause the app to restart and all pack requests to be cancelled.
These packs should be requested again after the app restarts.

The confirmation activity returns one of the following values:

- [Activity.RESULT_OK](https://developer.android.com/reference/android/app/Activity.html#RESULT_OK) if the user accepted.
- [Activity.RESULT_CANCELED](https://developer.android.com/reference/android/app/Activity.html#RESULT_CANCELED) if the user denied or the dialog has been closed in any other way (e.g. backpress).

<br />

<br />

|                                                       Parameters                                                        ||
|--------------------------|-----------------------------------------------------------------------------------------------|
| `activityResultLauncher` | `ActivityResultLauncher`: an activityResultLauncher to launch the confirmation dialog. <br /> |

|                               Returns                               ||
|-----------|----------------------------------------------------------|
| `boolean` | whether the confirmation dialog has been started. <br /> |

### unregisterListener

```
public abstract void unregisterListener (AiPackStateUpdateListener listener)
```

Unregisters a listener previously added using [registerListener(AiPackStateUpdateListener)](https://developer.android.com/reference/com/google/android/play/core/aipacks/AiPackManager.html#registerListener(com.google.android.play.core.aipacks.AiPackStateUpdateListener)).

<br />

|                   Parameters                   ||
|------------|------------------------------------|
| `listener` | `AiPackStateUpdateListener` <br /> |