DefaultDownloadIndex
@UnstableApi
public final class DefaultDownloadIndex implements WritableDownloadIndex
A DownloadIndex that uses SQLite to persist Downloads.
Summary
Public constructors |
|---|
DefaultDownloadIndex(DatabaseProvider databaseProvider)Creates an instance that stores the |
DefaultDownloadIndex(DatabaseProvider databaseProvider, String name)Creates an instance that stores the |
Public methods |
|
|---|---|
@Nullable Download |
getDownload(String id)Returns the |
DownloadCursor |
getDownloads(@Download.State int[] states)Returns a |
void |
putDownload(Download download)Adds or replaces a |
void |
removeDownload(String id)Removes the download with the given ID. |
void |
Sets all |
void |
Sets all states to |
void |
setStopReason(int stopReason)Sets the stop reason of the downloads in a terminal state ( |
void |
setStopReason(String id, int stopReason)Sets the stop reason of the download with the given ID in a terminal state ( |
Public constructors
DefaultDownloadIndex
public DefaultDownloadIndex(DatabaseProvider databaseProvider)
Creates an instance that stores the Downloads in an SQLite database provided by a DatabaseProvider.
Equivalent to calling DefaultDownloadIndex with
name="".
Applications that only have one download index may use this constructor. Applications that have multiple download indices should call DefaultDownloadIndex to specify a unique name for each index.
| Parameters | |
|---|---|
DatabaseProvider databaseProvider |
Provides the SQLite database in which downloads are persisted. |
DefaultDownloadIndex
public DefaultDownloadIndex(DatabaseProvider databaseProvider, String name)
Creates an instance that stores the Downloads in an SQLite database provided by a DatabaseProvider.
| Parameters | |
|---|---|
DatabaseProvider databaseProvider |
Provides the SQLite database in which downloads are persisted. |
String 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 Download with the given id, or null.
This method may be slow and shouldn't normally be called on the main thread.
| Returns | |
|---|---|
@Nullable Download |
The |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs reading the state. |
androidx.media3.database.DatabaseIOException |
getDownloads
public DownloadCursor getDownloads(@Download.State int[] states)
Returns a DownloadCursor to Downloads with the given states.
This method may be slow and shouldn't normally be called on the main thread.
| Parameters | |
|---|---|
@Download.State int[] states |
Returns only the |
| Returns | |
|---|---|
DownloadCursor |
A cursor to |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs reading the state. |
androidx.media3.database.DatabaseIOException |
putDownload
public void putDownload(Download download)
Adds or replaces a Download.
This method may be slow and shouldn't normally be called on the main thread.
| Throws | |
|---|---|
java.io.IOException |
If an error occurs setting the state. |
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 | |
|---|---|
String id |
The ID of the download to remove. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs removing the state. |
androidx.media3.database.DatabaseIOException |
setDownloadingStatesToQueued
public void setDownloadingStatesToQueued()
Sets all STATE_DOWNLOADING states to STATE_QUEUED.
This method may be slow and shouldn't normally be called on the main thread.
| Throws | |
|---|---|
java.io.IOException |
If an error occurs updating the state. |
androidx.media3.database.DatabaseIOException |
setStatesToRemoving
public void setStatesToRemoving()
Sets all states to STATE_REMOVING.
This method may be slow and shouldn't normally be called on the main thread.
| Throws | |
|---|---|
java.io.IOException |
If an error occurs updating the state. |
androidx.media3.database.DatabaseIOException |
setStopReason
public void setStopReason(int stopReason)
Sets the stop reason of the downloads in a terminal state (STATE_COMPLETED, STATE_FAILED).
This method may be slow and shouldn't normally be called on the main thread.
| Parameters | |
|---|---|
int stopReason |
The stop reason. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs updating the state. |
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 (STATE_COMPLETED, 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 | |
|---|---|
String id |
The ID of the download to update. |
int stopReason |
The stop reason. |
| Throws | |
|---|---|
java.io.IOException |
If an error occurs updating the state. |
androidx.media3.database.DatabaseIOException |