# DefaultDownloadIndex

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/DefaultDownloadIndex.java+class:androidx.media3.exoplayer.offline.DefaultDownloadIndex)

*** ** * ** ***


```
@UnstableApi
public final class DefaultDownloadIndex implements WritableDownloadIndex
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadIndex` that uses SQLite to persist `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#DefaultDownloadIndex(androidx.media3.database.DatabaseProvider)(https://developer.android.com/reference/androidx/media3/database/DatabaseProvider databaseProvider)` Creates an instance that stores the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` in an SQLite database provided by a `https://developer.android.com/reference/androidx/media3/database/DatabaseProvider`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#DefaultDownloadIndex(androidx.media3.database.DatabaseProvider,java.lang.String)(https://developer.android.com/reference/androidx/media3/database/DatabaseProvider databaseProvider, https://developer.android.com/reference/java/lang/String.html name)` Creates an instance that stores the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` in an SQLite database provided by a `https://developer.android.com/reference/androidx/media3/database/DatabaseProvider`. |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#getDownload(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` with the given `id`, or null. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadCursor` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#getDownloads(int...)(@https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.State int[] states)` Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadCursor` to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`s with the given `states`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#putDownload(androidx.media3.exoplayer.offline.Download)(https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download download)` Adds or replaces a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#removeDownload(java.lang.String)(https://developer.android.com/reference/java/lang/String.html id)` Removes the download with the given ID. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#setDownloadingStatesToQueued()()` Sets all `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_DOWNLOADING()` states to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_QUEUED()`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#setStatesToRemoving()()` Sets all states to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_REMOVING()`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#setStopReason(int)(int stopReason)` Sets the stop reason of the downloads in a terminal state (`https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`). |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#setStopReason(java.lang.String,int)(https://developer.android.com/reference/java/lang/String.html id, int stopReason)` Sets the stop reason of the download with the given ID in a terminal state (`https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`). |

## Public constructors

### DefaultDownloadIndex

```
public DefaultDownloadIndex(DatabaseProvider databaseProvider)
```

Creates an instance that stores the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` in an SQLite database provided by a `https://developer.android.com/reference/androidx/media3/database/DatabaseProvider`.

Equivalent to calling `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#DefaultDownloadIndex(androidx.media3.database.DatabaseProvider,java.lang.String)` with `
name=""`.

Applications that only have one download index may use this constructor. Applications that have multiple download indices should call `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DefaultDownloadIndex#DefaultDownloadIndex(androidx.media3.database.DatabaseProvider,java.lang.String)` to specify a unique name for each index.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/database/DatabaseProvider databaseProvider` | Provides the SQLite database in which downloads are persisted. |

### DefaultDownloadIndex

```
public DefaultDownloadIndex(DatabaseProvider databaseProvider, String name)
```

Creates an instance that stores the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` in an SQLite database provided by a `https://developer.android.com/reference/androidx/media3/database/DatabaseProvider`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/database/DatabaseProvider databaseProvider` | Provides the SQLite database in which downloads are persisted. |
| `https://developer.android.com/reference/java/lang/String.html name` | The name of the index. This name is incorporated into the names of the SQLite tables in which downloads are persisted. |

## Public methods

### getDownload

```
public @Nullable Download getDownload(String id)
```

Returns the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` with the given `id`, or null.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` | ID of a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` | The `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download` with the given `id`, or null if a download state with this id doesn't exist. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs reading the state. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseIOException` |   |

### getDownloads

```
public DownloadCursor getDownloads(@Download.State int[] states)
```

Returns a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadCursor` to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`s with the given `states`.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download.State int[] states` | Returns only the `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`s with this states. If empty, returns all. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/offline/DownloadCursor` | A cursor to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`s with the given `states`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs reading the state. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseIOException` |   |

### putDownload

```
public void putDownload(Download download)
```

Adds or replaces a `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download`.

This method may be slow and shouldn't normally be called on the main thread.

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

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs setting the state. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseIOException` |   |

### removeDownload

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

Removes the download with the given ID. Does nothing if a download with the given ID does not exist.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` | The ID of the download to remove. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs removing the state. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseIOException` |   |

### setDownloadingStatesToQueued

```
public void setDownloadingStatesToQueued()
```

Sets all `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_DOWNLOADING()` states to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_QUEUED()`.

This method may be slow and shouldn't normally be called on the main thread.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs updating the state. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseIOException` |   |

### setStatesToRemoving

```
public void setStatesToRemoving()
```

Sets all states to `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_REMOVING()`.

This method may be slow and shouldn't normally be called on the main thread.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs updating the state. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseIOException` |   |

### setStopReason

```
public void setStopReason(int stopReason)
```

Sets the stop reason of the downloads in a terminal state (`https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`).

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `int stopReason` | The stop reason. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs updating the state. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseIOException` |   |

### setStopReason

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

Sets the stop reason of the download with the given ID in a terminal state (`https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_COMPLETED()`, `https://developer.android.com/reference/androidx/media3/exoplayer/offline/Download#STATE_FAILED()`). Does nothing if a download with the given ID does not exist, or if it's not in a terminal state.

This method may be slow and shouldn't normally be called on the main thread.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html id` | The ID of the download to update. |
| `int stopReason` | The stop reason. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs updating the state. |
| `https://developer.android.com/reference/androidx/media3/database/DatabaseIOException` |   |