@UnstableApi
public final class Download


Represents state of a download.

Summary

Nested types

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

Failure reasons.

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

Download states.

Constants

static final int

The download isn't failed.

static final int

The download is failed because of unknown reason.

static final int

The download completed.

static final int

The download is currently started.

static final int

The download failed.

static final int

The download is waiting to be started.

static final int

The download is being removed.

static final int

The download will restart after all downloaded data is removed.

static final int

The download is stopped for a specified stopReason.

static final int

The download isn't stopped.

Public fields

final long

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

final int

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

final DownloadRequest

The download request.

final long

The first time when download entry is created.

final int

The state of the download.

final int

The reason the download is stopped, or STOP_REASON_NONE.

final long

The last update time.

Public constructors

Download(
    DownloadRequest request,
    @Download.State int state,
    long startTimeMs,
    long updateTimeMs,
    long contentLength,
    int stopReason,
    @Download.FailureReason int failureReason
)
Download(
    DownloadRequest request,
    @Download.State int state,
    long startTimeMs,
    long updateTimeMs,
    long contentLength,
    int stopReason,
    @Download.FailureReason int failureReason,
    DownloadProgress progress
)

Public methods

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.

Constants

FAILURE_REASON_NONE

public static final int FAILURE_REASON_NONE = 0

The download isn't failed.

FAILURE_REASON_UNKNOWN

public static final int FAILURE_REASON_UNKNOWN = 1

The download is failed because of unknown reason.

STATE_COMPLETED

public static final int STATE_COMPLETED = 3

The download completed.

STATE_DOWNLOADING

public static final int STATE_DOWNLOADING = 2

The download is currently started.

STATE_FAILED

public static final int STATE_FAILED = 4

The download failed.

STATE_QUEUED

public static final int STATE_QUEUED = 0

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

public static final int STATE_REMOVING = 5

The download is being removed.

STATE_RESTARTING

public static final int STATE_RESTARTING = 7

The download will restart after all downloaded data is removed.

STATE_STOPPED

public static final int STATE_STOPPED = 1

The download is stopped for a specified stopReason.

STOP_REASON_NONE

public static final int STOP_REASON_NONE = 0

The download isn't stopped.

Public fields

contentLength

public final long contentLength

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

failureReason

@Download.FailureReason
public final int failureReason

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

request

public final DownloadRequest request

The download request.

startTimeMs

public final long startTimeMs

The first time when download entry is created.

state

@Download.State
public final int state

The state of the download.

stopReason

public final int stopReason

The reason the download is stopped, or STOP_REASON_NONE.

updateTimeMs

public final long updateTimeMs

The last update time.

Public constructors

Download

public Download(
    DownloadRequest request,
    @Download.State int state,
    long startTimeMs,
    long updateTimeMs,
    long contentLength,
    int stopReason,
    @Download.FailureReason int failureReason
)

Download

public Download(
    DownloadRequest request,
    @Download.State int state,
    long startTimeMs,
    long updateTimeMs,
    long contentLength,
    int stopReason,
    @Download.FailureReason int failureReason,
    DownloadProgress progress
)

Public methods

getBytesDownloaded

public long getBytesDownloaded()

Returns the total number of downloaded bytes.

getPercentDownloaded

public float getPercentDownloaded()

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

isTerminalState

public boolean isTerminalState()

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