# DownloadAssetPackAsync

> Downloads Android asset packs.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Android](/engine/6000.7/script-reference/unityengine/android.md)
* **Assembly:** UnityEngine.AndroidJNIModule

## DownloadAssetPackAsync(string\[], Action\<AndroidAssetPackInfo>)

Downloads Android asset packs.

```csharp
public static void DownloadAssetPackAsync(string[] assetPackNames, Action<AndroidAssetPackInfo> callback)
```

### Parameters

**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): The array of names of Android asset packs to download.**** (\[Action\<AndroidAssetPackInfo>]\(https\://learn.microsoft.com/dotnet/api/system.action)): The callback method to inform about download progress. It gets called multiple times for each asset pack during its download. The callback method must have a parameter of AndroidAssetPackInfo type. The default value is null.

### Remarks

This method directly wraps Google's [PlayCore plug-in](https://developer.android.com/guide/playcore) API. If the PlayCore plug-in is missing, calling this method throws an `InvalidOperationException`.

Additional Resources: [AndroidAssetPackInfo](/engine/6000.7/script-reference/unityengine/android/androidassetpackinfo.md), [AndroidAssetPacks.CancelAssetPackDownload](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/cancelassetpackdownload.md), [AndroidAssetPacks.GetAssetPackPath](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/getassetpackpath.md), [AndroidAssetPacks.GetAssetPackStateAsync](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/getassetpackstateasync.md), [AndroidAssetPacks.RemoveAssetPack](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/removeassetpack.md), [AndroidAssetPacks.ShowConfirmationDialogAsync](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/showconfirmationdialogasync.md)

### Examples

```csharp
using UnityEngine;
using UnityEngine.Android;

public class DownloadAssetPackCallbackExample : MonoBehaviour
{
    bool isShowingDialog = false;

    void Start()
    {
        AndroidAssetPacks.DownloadAssetPackAsync(
            new string[] { "MyAssetPack" },
            OnDownloadProgress
        );
    }

    void OnDownloadProgress(AndroidAssetPackInfo info)
    {
        switch (info.status)
        {
            case AndroidAssetPackStatus.Pending:
                Debug.Log($"{info.name}: Pending");
                break;
            case AndroidAssetPackStatus.Downloading:
                float percentComplete = info.size > 0
                    ? (float)info.bytesDownloaded / info.size * 100f
                    : 0f;
                Debug.Log($"{info.name}: Downloading {percentComplete:F1}%");
                break;
            case AndroidAssetPackStatus.Transferring:
                Debug.Log($"{info.name}: Transferring {(info.transferProgress * 100f):F1}%");
                break;
            case AndroidAssetPackStatus.Completed:
                var path = AndroidAssetPacks.GetAssetPackPath(info.name);
                Debug.Log($"{info.name}: Completed. Path: {path}");
                break;
            case AndroidAssetPackStatus.Failed:
                Debug.LogError($"{info.name}: Failed with error {info.error}");
                break;
            case AndroidAssetPackStatus.WaitingForWifi:
            case AndroidAssetPackStatus.RequiresUserConfirmation:
                if (!isShowingDialog)
                {
                    isShowingDialog = true;
                    Debug.Log(info.status == AndroidAssetPackStatus.WaitingForWifi
                        ? $"{info.name}: Download paused until connected to Wi-Fi."
                        : $"{info.name}: Download requires user confirmation.");
                    AndroidAssetPacks.ShowConfirmationDialogAsync(result =>
                    {
                        isShowingDialog = false;
                        Debug.Log(result.consentGiven
                            ? "User gave consent. Downloads will resume."
                            : "User denied consent.");
                    });
                }
                break;
            case AndroidAssetPackStatus.Canceled:
                Debug.Log($"{info.name}: Download canceled.");
                break;
            case AndroidAssetPackStatus.NotInstalled:
                Debug.Log($"{info.name}: Android asset pack is not installed");
                break;
            default:
                Debug.Log($"{info.name}: Status {info.status}");
                break;
        }
    }
}
```

## DownloadAssetPackAsync(string\[])

Downloads Android asset packs to the device.

```csharp
public static DownloadAssetPackAsyncOperation DownloadAssetPackAsync(string[] assetPackNames)
```

### Parameters

**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): The array of names of Android asset packs to download.

### Returns

| Type                                                                                                                      | Description                                                                                                                                          |
| ------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| [DownloadAssetPackAsyncOperation](/engine/6000.7/script-reference/unityengine/android/downloadassetpackasyncoperation.md) | An object that represents the download operation. If you yield this object inside a coroutine, the coroutine pauses until the operation is complete. |

### Remarks

This method directly wraps Google's [PlayCore plug-in](https://developer.android.com/guide/playcore) API. If the PlayCore plug-in is missing, calling this method throws an `InvalidOperationException`.

Additional Resources: [DownloadAssetPackAsyncOperation](/engine/6000.7/script-reference/unityengine/android/downloadassetpackasyncoperation.md), [AndroidAssetPackInfo](/engine/6000.7/script-reference/unityengine/android/androidassetpackinfo.md), [AndroidAssetPacks.CancelAssetPackDownload](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/cancelassetpackdownload.md), [AndroidAssetPacks.GetAssetPackPath](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/getassetpackpath.md), [AndroidAssetPacks.GetAssetPackStateAsync](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/getassetpackstateasync.md), [AndroidAssetPacks.RemoveAssetPack](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/removeassetpack.md), [AndroidAssetPacks.ShowConfirmationDialogAsync](/engine/6000.7/script-reference/unityengine/android/androidassetpacks/showconfirmationdialogasync.md)

### Examples

```csharp
using System.Collections;
using UnityEngine;
using UnityEngine.Android;

public class DownloadAssetPackAsyncExample : MonoBehaviour
{
    IEnumerator Start()
    {
        var assetPackNames = new string[] { "MyAssetPack" };

        var downloadOperation = AndroidAssetPacks.DownloadAssetPackAsync(assetPackNames);

        // Yield until the download completes.
        yield return downloadOperation;

        if (downloadOperation.downloadedAssetPacks.Length == 0)
        {
            Debug.LogWarning("No asset packs were downloaded.");
        }

        foreach (var packName in downloadOperation.downloadedAssetPacks)
        {
            var path = AndroidAssetPacks.GetAssetPackPath(packName);
            Debug.Log($"Asset pack downloaded to: {path}");
        }

        foreach (var failedPack in downloadOperation.downloadFailedAssetPacks)
        {
            Debug.LogError($"Failed to download asset pack: {failedPack}");
        }
    }
}
```
