Download
@UnstableApi
public final class Download
Represents state of a download.
Summary
Nested types |
---|
@Documented Failure reasons. |
@Documented 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 |
STATE_COMPLETED = 3 The download completed. |
static final int |
The download is currently started. |
static final int |
STATE_FAILED = 4 The download failed. |
static final int |
STATE_QUEUED = 0 The download is waiting to be started. |
static final int |
STATE_REMOVING = 5 The download is being removed. |
static final int |
STATE_RESTARTING = 7 The download will restart after all downloaded data is removed. |
static final int |
STATE_STOPPED = 1 The download is stopped for a specified |
static final int |
STOP_REASON_NONE = 0 The download isn't stopped. |
Public fields |
|
---|---|
final long |
The total size of the content in bytes, or |
final int |
If |
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 |
final long |
The last update time. |
Public constructors |
---|
Download( |
Download( |
Public methods |
|
---|---|
long |
Returns the total number of downloaded bytes. |
float |
Returns the estimated download percentage, or |
boolean |
Returns whether the download is completed or failed. |
Constants
FAILURE_REASON_UNKNOWN
public static final int FAILURE_REASON_UNKNOWN = 1
The download is failed because of unknown reason.
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_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
.
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
.
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
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.