@UnstableApi
class Download


Represents state of a download.

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
annotation Download.FailureReason

Failure reasons.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
annotation Download.State

Download states.

Constants

const Int

The download isn't failed.

const Int

The download is failed because of unknown reason.

const Int

The download completed.

const Int

The download is currently started.

const Int

The download failed.

const Int

The download is waiting to be started.

const Int

The download is being removed.

const Int

The download will restart after all downloaded data is removed.

const Int

The download is stopped for a specified stopReason.

const Int

The download isn't stopped.

Public constructors

Download(
    request: DownloadRequest!,
    @Download.State state: Int,
    startTimeMs: Long,
    updateTimeMs: Long,
    contentLength: Long,
    stopReason: Int,
    @Download.FailureReason failureReason: Int
)
Download(
    request: DownloadRequest!,
    @Download.State state: Int,
    startTimeMs: Long,
    updateTimeMs: Long,
    contentLength: Long,
    stopReason: Int,
    @Download.FailureReason failureReason: Int,
    progress: DownloadProgress!
)

Public functions

Long

Returns the total number of downloaded bytes.

Float

Returns the estimated download percentage, or PERCENTAGE_UNSET if no estimate is available.

Boolean

Returns whether the download is completed or failed.

Public properties

Long

The total size of the content in bytes, or LENGTH_UNSET if unknown.

Int

If state is STATE_FAILED then this is the cause, otherwise FAILURE_REASON_NONE.

DownloadRequest!

The download request.

Long

The first time when download entry is created.

Int

The state of the download.

Int

The reason the download is stopped, or STOP_REASON_NONE.

Long

The last update time.

Constants

FAILURE_REASON_NONE

const val FAILURE_REASON_NONE = 0: Int

The download isn't failed.

FAILURE_REASON_UNKNOWN

const val FAILURE_REASON_UNKNOWN = 1: Int

The download is failed because of unknown reason.

STATE_COMPLETED

const val STATE_COMPLETED = 3: Int

The download completed.

STATE_DOWNLOADING

const val STATE_DOWNLOADING = 2: Int

The download is currently started.

STATE_FAILED

const val STATE_FAILED = 4: Int

The download failed.

STATE_QUEUED

const val STATE_QUEUED = 0: Int

The download is waiting to be started. A download may be queued because the DownloadManager

  • Is DownloadManager#getDownloadsPaused() paused
  • Has DownloadManager#getRequirements() Requirements that are not met
  • Has already started DownloadManager#getMaxParallelDownloads() maxParallelDownloads

STATE_REMOVING

const val STATE_REMOVING = 5: Int

The download is being removed.

STATE_RESTARTING

const val STATE_RESTARTING = 7: Int

The download will restart after all downloaded data is removed.

STATE_STOPPED

const val STATE_STOPPED = 1: Int

The download is stopped for a specified stopReason.

STOP_REASON_NONE

const val STOP_REASON_NONE = 0: Int

The download isn't stopped.

Public constructors

Download

Download(
    request: DownloadRequest!,
    @Download.State state: Int,
    startTimeMs: Long,
    updateTimeMs: Long,
    contentLength: Long,
    stopReason: Int,
    @Download.FailureReason failureReason: Int
)

Download

Download(
    request: DownloadRequest!,
    @Download.State state: Int,
    startTimeMs: Long,
    updateTimeMs: Long,
    contentLength: Long,
    stopReason: Int,
    @Download.FailureReason failureReason: Int,
    progress: DownloadProgress!
)

Public functions

getBytesDownloaded

fun getBytesDownloaded(): Long

Returns the total number of downloaded bytes.

getPercentDownloaded

fun getPercentDownloaded(): Float

Returns the estimated download percentage, or PERCENTAGE_UNSET if no estimate is available.

isTerminalState

fun isTerminalState(): Boolean

Returns whether the download is completed or failed. These are terminal states.

Public properties

contentLength

val contentLengthLong

The total size of the content in bytes, or LENGTH_UNSET if unknown.

failureReason

@Download.FailureReason
val failureReasonInt

If state is STATE_FAILED then this is the cause, otherwise FAILURE_REASON_NONE.

request

val requestDownloadRequest!

The download request.

startTimeMs

val startTimeMsLong

The first time when download entry is created.

state

@Download.State
val stateInt

The state of the download.

stopReason

val stopReasonInt

The reason the download is stopped, or STOP_REASON_NONE.

updateTimeMs

val updateTimeMsLong

The last update time.