# DownloadManager

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/offline/DownloadManager.java+class:androidx.media3.exoplayer.offline.DownloadManager)

*** ** * ** ***


```
@UnstableApi
public final class DownloadManager
```

<br />

*** ** * ** ***

Manages downloads.

Normally a download manager should be accessed via a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadService`. When a download manager is used directly instead, downloads will be initially paused and so must be resumed by calling `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#resumeDownloads()`.

A download manager instance must be accessed only from the thread that created it, unless that thread does not have a `https://developer.android.com/reference/android/os/Looper.html`. In that case, it must be accessed only from the application's main thread. Registered listeners will be called on the same thread. In all cases the `Looper` of the thread from which the manager must be accessed can be queried using `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getApplicationLooper()`.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener` Listener for `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager` events. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#DEFAULT_MAX_PARALLEL_DOWNLOADS() = 3` The default maximum number of parallel downloads. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#DEFAULT_MIN_RETRY_COUNT() = 5` The default minimum number of times a download must be retried before failing. |
| `static final https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#DEFAULT_REQUIREMENTS()` The default requirement is that the device has network connectivity. |

| ### Public fields |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#downloadsPaused()` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#maxParallelDownloads()` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#minRetryCount()` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#notMetRequirements()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#DownloadManager(android.content.Context,androidx.media3.exoplayer.offline.WritableDownloadIndex,androidx.media3.exoplayer.offline.DownloaderFactory)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/androidx/media3/exoplayer/offline/WritableDownloadIndex downloadIndex, https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloaderFactory downloaderFactory )` Constructs a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#DownloadManager(android.content.Context,androidx.media3.database.DatabaseProvider,androidx.media3.datasource.cache.Cache,androidx.media3.datasource.DataSource.Factory,java.util.concurrent.Executor)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/androidx/media3/database/DatabaseProvider databaseProvider, https://developer.android.com/reference/androidx/media3/datasource/cache/Cache cache, https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory upstreamFactory, https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Constructs a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager`. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#addDownload(androidx.media3.exoplayer.offline.DownloadRequest)(https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest request)` Adds a download defined by the given request. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#addDownload(androidx.media3.exoplayer.offline.DownloadRequest,int)(https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest request, int stopReason)` Adds a download defined by the given request and with the specified stop reason. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#addListener(androidx.media3.exoplayer.offline.DownloadManager.Listener)(https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener listener)` Adds a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener`. |
| `https://developer.android.com/reference/android/os/Looper.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getApplicationLooper()()` Returns the `https://developer.android.com/reference/android/os/Looper.html` associated with the application thread that's used to access the manager, and on which the manager will call its `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener`. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download>` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getCurrentDownloads()()` Returns current downloads. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadIndex` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getDownloadIndex()()` Returns the used `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadIndex`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getDownloadsPaused()()` Returns whether downloads are currently paused. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getMaxParallelDownloads()()` Returns the maximum number of parallel downloads. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getMinRetryCount()()` Returns the minimum number of times that a download will be retried. |
| `int` | `@https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements.RequirementFlags https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getNotMetRequirements()()` Returns the requirements needed for downloads to progress that are not currently met. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getRequirements()()` Returns the requirements needed to be met to progress. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#isIdle()()` Returns whether the manager is currently idle. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#isInitialized()()` Returns whether the manager has completed initialization. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#isWaitingForRequirements()()` Returns whether this manager has one or more downloads that are not progressing for the sole reason that the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getRequirements()` are not met. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#pauseDownloads()()` Pauses downloads. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#release()()` Stops the downloads and releases resources. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#removeAllDownloads()()` Cancels all pending downloads and removes all downloaded data. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#removeDownload(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Cancels the download with the `id` and removes all downloaded data. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#removeListener(androidx.media3.exoplayer.offline.DownloadManager.Listener)(https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener listener)` Removes a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#resumeDownloads()()` Resumes downloads. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#setMaxParallelDownloads(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int maxParallelDownloads)` Sets the maximum number of parallel downloads. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#setMinRetryCount(int)(int minRetryCount)` Sets the minimum number of times that a download will be retried. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#setRequirements(androidx.media3.exoplayer.scheduler.Requirements)(https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements requirements)` Sets the requirements that need to be met for downloads to progress. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#setStopReason(java.lang.String,int)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html id, int stopReason)` Sets the stop reason for one or all downloads. |

## Constants

### DEFAULT_MAX_PARALLEL_DOWNLOADS

```
public static final int DEFAULT_MAX_PARALLEL_DOWNLOADS = 3
```

The default maximum number of parallel downloads.

### DEFAULT_MIN_RETRY_COUNT

```
public static final int DEFAULT_MIN_RETRY_COUNT = 5
```

The default minimum number of times a download must be retried before failing.

### DEFAULT_REQUIREMENTS

```
public static final Requirements DEFAULT_REQUIREMENTS
```

The default requirement is that the device has network connectivity.

## Public fields

### downloadsPaused

```
public boolean downloadsPaused
```

### maxParallelDownloads

```
public int maxParallelDownloads
```

### minRetryCount

```
public int minRetryCount
```

### notMetRequirements

```
public int notMetRequirements
```

## Public constructors

### DownloadManager

```
public DownloadManager(
    Context context,
    WritableDownloadIndex downloadIndex,
    DownloaderFactory downloaderFactory
)
```

Constructs a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | Any context. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/WritableDownloadIndex downloadIndex` | The download index used to hold the download information. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloaderFactory downloaderFactory` | A factory for creating `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Downloader`s. |

### DownloadManager

```
public DownloadManager(
    Context context,
    DatabaseProvider databaseProvider,
    Cache cache,
    DataSource.Factory upstreamFactory,
    Executor executor
)
```

Constructs a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | Any context. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseProvider databaseProvider` | Provides the SQLite database in which downloads are persisted. |
| `https://developer.android.com/reference/androidx/media3/datasource/cache/Cache cache` | A cache to be used to store downloaded data. The cache should be configured with an `https://developer.android.com/reference/androidx/media3/datasource/cache/CacheEvictor` that will not evict downloaded content, for example `https://developer.android.com/reference/androidx/media3/datasource/cache/NoOpCacheEvictor`. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory upstreamFactory` | A `https://developer.android.com/reference/androidx/media3/datasource/DataSource.Factory` for creating `https://developer.android.com/reference/androidx/media3/datasource/DataSource`s for downloading data. |
| `https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | An `https://developer.android.com/reference/java/util/concurrent/Executor.html` used to download data. Passing `Runnable::run` will cause each download task to download data on its own thread. Passing an `https://developer.android.com/reference/java/util/concurrent/Executor.html` that uses multiple threads will speed up download tasks that can be split into smaller parts for parallel execution. |

## Public methods

### addDownload

```
public void addDownload(DownloadRequest request)
```

Adds a download defined by the given request.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest request` | The download request. |

### addDownload

```
public void addDownload(DownloadRequest request, int stopReason)
```

Adds a download defined by the given request and with the specified stop reason.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadRequest request` | The download request. |
| `int stopReason` | An initial stop reason for the download, or `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STOP_REASON_NONE()` if the download should be started. |

### addListener

```
public void addListener(DownloadManager.Listener listener)
```

Adds a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener listener` | The listener to be added. |

### getApplicationLooper

```
public Looper getApplicationLooper()
```

Returns the `https://developer.android.com/reference/android/os/Looper.html` associated with the application thread that's used to access the manager, and on which the manager will call its `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener`.

### getCurrentDownloads

```
public List<Download> getCurrentDownloads()
```

Returns current downloads. Downloads that are in terminal states (i.e. completed or failed) are not included. To query all downloads including those in terminal states, use `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getDownloadIndex()` instead.

### getDownloadIndex

```
public DownloadIndex getDownloadIndex()
```

Returns the used `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadIndex`.

### getDownloadsPaused

```
public boolean getDownloadsPaused()
```

Returns whether downloads are currently paused.

### getMaxParallelDownloads

```
public int getMaxParallelDownloads()
```

Returns the maximum number of parallel downloads.

### getMinRetryCount

```
public int getMinRetryCount()
```

Returns the minimum number of times that a download will be retried. A download will fail if the specified number of retries is exceeded without any progress being made.

### getNotMetRequirements

```
@Requirements.RequirementFlags
public int getNotMetRequirements()
```

Returns the requirements needed for downloads to progress that are not currently met.

| Returns |
|---|---|
| `int` | The not met `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements.RequirementFlags`, or 0 if all requirements are met. |

### getRequirements

```
public Requirements getRequirements()
```

Returns the requirements needed to be met to progress.

### isIdle

```
public boolean isIdle()
```

Returns whether the manager is currently idle. The manager is idle if all downloads are in a terminal state (i.e. completed or failed), or if no progress can be made (e.g. because the download requirements are not met).

### isInitialized

```
public boolean isInitialized()
```

Returns whether the manager has completed initialization.

### isWaitingForRequirements

```
public boolean isWaitingForRequirements()
```

Returns whether this manager has one or more downloads that are not progressing for the sole reason that the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getRequirements()` are not met. This is true if:

- The `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getRequirements()` are not met.
- The downloads are not paused (i.e. `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getDownloadsPaused()` is `false`).
- There are downloads in the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_QUEUED()`.

### pauseDownloads

```
public void pauseDownloads()
```

Pauses downloads. Downloads that would otherwise be making progress will transition to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_QUEUED()`.

### release

```
public void release()
```

Stops the downloads and releases resources. Waits until the downloads are persisted to the download index. The manager must not be accessed after this method has been called.

### removeAllDownloads

```
public void removeAllDownloads()
```

Cancels all pending downloads and removes all downloaded data.

### removeDownload

```
public void removeDownload(String id)
```

Cancels the download with the `id` and removes all downloaded data.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` | The unique content id of the download to be started. |

### removeListener

```
public void removeListener(DownloadManager.Listener listener)
```

Removes a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager.Listener listener` | The listener to be removed. |

### resumeDownloads

```
public void resumeDownloads()
```

Resumes downloads.

If the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#setRequirements(androidx.media3.exoplayer.scheduler.Requirements)` are met up to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadManager#getMaxParallelDownloads()` will be started, excluding those with non-zero `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#stopReason()`.

### setMaxParallelDownloads

```
public void setMaxParallelDownloads(@IntRange(from = 1) int maxParallelDownloads)
```

Sets the maximum number of parallel downloads.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int maxParallelDownloads` | The maximum number of parallel downloads. Must be greater than 0. |

### setMinRetryCount

```
public void setMinRetryCount(int minRetryCount)
```

Sets the minimum number of times that a download will be retried. A download will fail if the specified number of retries is exceeded without any progress being made.

| Parameters |
|---|---|
| `int minRetryCount` | The minimum number of times that a download will be retried. |

### setRequirements

```
public void setRequirements(Requirements requirements)
```

Sets the requirements that need to be met for downloads to progress.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements requirements` | A `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements`. |

### setStopReason

```
public void setStopReason(@Nullable String id, int stopReason)
```

Sets the stop reason for one or all downloads. To clear the stop reason, pass `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STOP_REASON_NONE()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html id` | The content id of the download to update, or `null` to set the stop reason for all downloads. |
| `int stopReason` | The stop reason, or `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STOP_REASON_NONE()`. |