DefaultDownloadIndex


@UnstableApi
class DefaultDownloadIndex : WritableDownloadIndex


A DownloadIndex that uses SQLite to persist Downloads.

Summary

Public constructors

Creates an instance that stores the Downloads in an SQLite database provided by a DatabaseProvider.

DefaultDownloadIndex(databaseProvider: DatabaseProvider!, name: String!)

Creates an instance that stores the Downloads in an SQLite database provided by a DatabaseProvider.

Public functions

Download?

Returns the Download with the given id, or null.

DownloadCursor!

Returns a DownloadCursor to Downloads with the given states.

Unit
putDownload(download: Download!)

Adds or replaces a Download.

Unit

Removes the download with the given ID.

Unit

Sets all STATE_DOWNLOADING states to STATE_QUEUED.

Unit

Sets all states to STATE_REMOVING.

Unit
setStopReason(stopReason: Int)

Sets the stop reason of the downloads in a terminal state (STATE_COMPLETED, STATE_FAILED).

Unit
setStopReason(id: String!, stopReason: Int)

Sets the stop reason of the download with the given ID in a terminal state (STATE_COMPLETED, STATE_FAILED).

Public constructors

DefaultDownloadIndex

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

DefaultDownloadIndex(databaseProvider: DatabaseProvider!, name: String!)

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.

name: String!

The name of the index. This name is incorporated into the names of the SQLite tables in which downloads are persisted.

Public functions

getDownload

fun getDownload(id: String!): Download?

Returns the Download with the given id, or null.

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

Parameters
id: String!

ID of a Download.

Returns
Download?

The Download with the given id, or null if a download state with this id doesn't exist.

Throws
java.io.IOException

If an error occurs reading the state.

androidx.media3.database.DatabaseIOException

getDownloads

fun getDownloads(@Download.State states: IntArray!): DownloadCursor!

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 states: IntArray!

Returns only the Downloads with this states. If empty, returns all.

Returns
DownloadCursor!

A cursor to Downloads with the given states.

Throws
java.io.IOException

If an error occurs reading the state.

androidx.media3.database.DatabaseIOException

putDownload

fun putDownload(download: Download!): Unit

Adds or replaces a Download.

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

Parameters
download: Download!

The Download to be added.

Throws
java.io.IOException

If an error occurs setting the state.

androidx.media3.database.DatabaseIOException

removeDownload

fun removeDownload(id: String!): Unit

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
id: String!

The ID of the download to remove.

Throws
java.io.IOException

If an error occurs removing the state.

androidx.media3.database.DatabaseIOException

setDownloadingStatesToQueued

fun setDownloadingStatesToQueued(): Unit

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

fun setStatesToRemoving(): Unit

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

fun setStopReason(stopReason: Int): Unit

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
stopReason: Int

The stop reason.

Throws
java.io.IOException

If an error occurs updating the state.

androidx.media3.database.DatabaseIOException

setStopReason

fun setStopReason(id: String!, stopReason: Int): Unit

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
id: String!

The ID of the download to update.

stopReason: Int

The stop reason.

Throws
java.io.IOException

If an error occurs updating the state.

androidx.media3.database.DatabaseIOException