public static class DownloadConfig.Builder extends Object
Builder objects of download configuration,
including methods to set parameters used to create a download session.| 构造器 | 说明 |
|---|---|
Builder(Context context,
Uri uri) |
A constructor used to create a
Builder instance for download session configuration. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
DownloadConfig.Builder |
addHttpheader(String header,
String content) |
Adds an HTTP or HTTPS header to be included with the download request.
|
DownloadConfig |
build() |
Creates a
DownloadConfig object. |
DownloadConfig.Builder |
enableMetered(boolean flag) |
Allows download under a metered connection.
|
DownloadConfig.Builder |
enableRoaming(boolean flag) |
Allows download in a roaming network.
|
DownloadConfig.Builder |
setDescription(String description) |
Sets the description of a download session.
|
DownloadConfig.Builder |
setDownloadRange(int offset,
int size) |
Sets the start offset and size for the fragment download request.
|
DownloadConfig.Builder |
setNetworkRestriction(int flag) |
Sets the network type allowed for download.
|
DownloadConfig.Builder |
setPath(String dir,
String subPath) |
Sets the path for downloads.
|
DownloadConfig.Builder |
setTitle(String title) |
Sets a download session title.
|
public Builder(Context context, Uri uri)
Builder instance for download session configuration.context - Indicates the application context.uri - Indicates an HTTP URI referenced to the file to be download.IllegalArgumentException - context is null, uri scheme is not http or https.public DownloadConfig.Builder setPath(String dir, String subPath)
Downloaded files can be stored in an application directory or a public system directory.
dir - Indicates a path.
To download files to a system directory, use one defined in ohos.utils.Environment,
for example, ohos.utils.Environment#DIRECTORY_DOWNLOAD,
ohos.utils.Environment#DIRECTORY_MUSIC,
and ohos.utils.Environment#DIRECTORY_PODCASTS.
To download files to an internal path of the application, set this parameter to null.
subPath - Indicates a subpath containing the name of the downloads.Builder object.IllegalStateException - Throws this exception if the path is invalid.NullPointerException - Throws this exception if subPath is null.public DownloadConfig.Builder addHttpheader(String header, String content)
The header will be added to the end of the list.
header - Indicates the HTTP header name.content - Indicates the HTTP header value.Builder object.NullPointerException - header is null.IllegalArgumentException - http header may not contain ':'.public DownloadConfig.Builder setTitle(String title)
If system download notifications are enabled for the application, the title will be displayed in the download session notification.
title - Indicates the download session title.Builder object.public DownloadConfig.Builder setDescription(String description)
If system download notifications are enabled for the application, the description will be displayed in the download session notification.
description - Indicates the description of the download session.Builder object.public DownloadConfig.Builder setNetworkRestriction(int flag)
By default, both of the two network types are allowed.
flag - Indicates the network type, which can be a combination of bit flags for the
cellular network and WLAN.Builder object.DownloadConfig.NETWORK_MOBILE,
DownloadConfig.NETWORK_WIFIpublic DownloadConfig.Builder setDownloadRange(int offset, int size)
offset - Indicates the offset (bytes) from which the download starts. The default value
is -1. A negative value means that the download starts from the file header.size - Indicates the size of each fragment, in bytes. The default value is 0.
Only a value greater than 0 takes effect, which indicates that the download ends at
offset + size. If the sum exceeds the target file size or size is
set to a negative value, the download ends where the file ends.Builder object.public DownloadConfig.Builder enableRoaming(boolean flag)
flag - Indicates whether download is allowed in a roaming network.
Value true means it is allowed, and false means the opposite.Builder object.public DownloadConfig.Builder enableMetered(boolean flag)
flag - Indicates whether to allow download when using a metered connection.
Value true means this is allowed, and false means the opposite.Builder object.public DownloadConfig build()
DownloadConfig object.