public static class DownloadManager.Request
extends Object
| java.lang.Object | |
| android.app.DownloadManager.Request | |
该类包含请求新下载所需的全部信息。 URI是唯一需要的参数。 请注意,默认下载目标是共享卷,如果系统需要回收系统使用空间,系统可能会删除您的文件。 如果这是一个问题,请在外部存储上使用位置(请参阅setDestinationUri(Uri) 。
常量(Constants) |
|
|---|---|
int |
NETWORK_MOBILE |
int |
NETWORK_WIFI
|
int |
VISIBILITY_HIDDEN 该下载不会在用户界面或通知中显示。 |
int |
VISIBILITY_VISIBLE 该下载是可见的,但仅在通知正在进行时显示。 |
int |
VISIBILITY_VISIBLE_NOTIFY_COMPLETED 该下载是可见的,并在进行中和完成后显示在通知中。 |
int |
VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION 此下载仅在完成后显示在通知中。 |
Public constructors |
|
|---|---|
DownloadManager.Request(Uri uri) |
|
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
int NETWORK_MOBILE
setAllowedNetworkTypes(int)位标志对应于 TYPE_MOBILE 。
常数值:1(0x00000001)
int NETWORK_WIFI
setAllowedNetworkTypes(int)位标志对应于 TYPE_WIFI 。
常量值:2(0x00000002)
int VISIBILITY_VISIBLE
该下载是可见的,但仅在通知正在进行时显示。
常量值:0(0x00000000)
int VISIBILITY_VISIBLE_NOTIFY_COMPLETED
该下载是可见的,并在进行中和完成后显示在通知中。
常数值:1(0x00000001)
int VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION
此下载仅在完成后显示在通知中。 这只适用于addCompletedDownload(String, String, boolean, String, String, long, boolean) 。
常量值:3(0x00000003)
DownloadManager.Request (Uri uri)
| 参数(Parameters) | |
|---|---|
uri |
Uri: the HTTP or HTTPS URI to download. |
DownloadManager.Request addRequestHeader (String header, String value)
添加一个HTTP头以包含在下载请求中。 标题将被添加到列表的末尾。
| 参数(Parameters) | |
|---|---|
header |
String: HTTP header name |
value |
String: header value |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
也可以看看:
void allowScanningByMediaScanner ()
如果要下载的文件要由MediaScanner扫描,则应在调用 enqueue(Request)之前调用此方法。
DownloadManager.Request setAllowedNetworkTypes (int flags)
限制可以继续下载的网络类型。 默认情况下,所有网络类型都是允许的。 考虑使用setAllowedOverMetered(boolean) ,因为它更灵活。
作为 N ,只将 NETWORK_WIFI这里标志等同于调用 setAllowedOverMetered(boolean)与 false 。
| 参数(Parameters) | |
|---|---|
flags |
int: any combination of the NETWORK_* bit flags. |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
DownloadManager.Request setAllowedOverMetered (boolean allow)
设置此下载是否可以通过计量的网络连接进行。 默认情况下,允许测量网络。
| 参数(Parameters) | |
|---|---|
allow |
boolean
|
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
|
也可以看看:
DownloadManager.Request setAllowedOverRoaming (boolean allowed)
设置此下载是否可以通过漫游连接继续。 默认情况下,允许漫游。
| 参数(Parameters) | |
|---|---|
allowed |
boolean: whether to allow a roaming connection to be used |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
DownloadManager.Request setDescription (CharSequence description)
设置此下载的说明,以显示在通知中(如果启用)
| 参数(Parameters) | |
|---|---|
description |
CharSequence
|
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
DownloadManager.Request setDestinationInExternalFilesDir (Context context, String dirType, String subPath)
将下载文件的本地目标设置为应用程序外部文件目录中的路径(由 getExternalFilesDir(String)返回。
MediaScanner不扫描下载的文件。 但可以通过调用allowScanningByMediaScanner()进行扫描。
| 参数(Parameters) | |
|---|---|
context |
Context: the Context to use in determining the external files directory |
dirType |
String: the directory type to pass to getExternalFilesDir(String) |
subPath |
String: the path within the external directory, including the destination filename |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
| 抛出异常(Throws) | |
|---|---|
IllegalStateException |
If the external storage directory cannot be found or created. |
DownloadManager.Request setDestinationInExternalPublicDir (String dirType, String subPath)
将下载文件的本地目标设置为公用外部存储目录中的路径(由 getExternalStoragePublicDirectory(String)返回)。
MediaScanner不扫描下载的文件。 但可以通过拨打allowScanningByMediaScanner()进行扫描。
| 参数(Parameters) | |
|---|---|
dirType |
String: the directory type to pass to getExternalStoragePublicDirectory(String) |
subPath |
String: the path within the external directory, including the destination filename |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
| 抛出异常(Throws) | |
|---|---|
IllegalStateException |
If the external storage directory cannot be found or created. |
DownloadManager.Request setDestinationUri (Uri uri)
设置下载文件的本地目标。 必须是外部存储器上路径的文件URI,并且调用应用程序必须具有WRITE_EXTERNAL_STORAGE权限。
MediaScanner不扫描下载的文件。 但可以通过拨打allowScanningByMediaScanner()进行扫描。
默认情况下,下载将保存到共享下载缓存中生成的文件名中,并可由系统在任何时候删除以回收空间。
| 参数(Parameters) | |
|---|---|
uri |
Uri
|
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
DownloadManager.Request setMimeType (String mimeType)
设置此下载的MIME内容类型。 这将覆盖服务器响应中声明的内容类型。
| 参数(Parameters) | |
|---|---|
mimeType |
String
|
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
也可以看看:
DownloadManager.Request setNotificationVisibility (int visibility)
控制下载管理器在下载运行或完成时是否发布系统通知。 如果启用,则下载管理器发布有关通过系统NotificationManager下载的通知。 默认情况下,只有在下载过程中才会显示通知。
它可以采取以下值: VISIBILITY_HIDDEN , VISIBILITY_VISIBLE , VISIBILITY_VISIBLE_NOTIFY_COMPLETED 。
如果设置为 VISIBILITY_HIDDEN ,则需要权限android.permission.DOWNLOAD_WITHOUT_NOTIFICATION。
| 参数(Parameters) | |
|---|---|
visibility |
int: the visibility setting value |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
DownloadManager.Request setRequiresCharging (boolean requiresCharging)
指定要运行此下载,需要插入设备。默认设置为false。
| 参数(Parameters) | |
|---|---|
requiresCharging |
boolean: Whether or not the device is plugged in. |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
|
也可以看看:
DownloadManager.Request setRequiresDeviceIdle (boolean requiresDeviceIdle)
指定要运行,下载需要设备处于空闲模式。 这默认为false。
空闲模式是由系统提供的松散定义,这意味着设备未被使用,并且一段时间未被使用。
| 参数(Parameters) | |
|---|---|
requiresDeviceIdle |
boolean: Whether or not the device need be within an idle maintenance window. |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
|
DownloadManager.Request setShowRunningNotification (boolean show)
此方法在API级别11中已弃用。
使用setNotificationVisibility(int)
控制在此下载运行时是否由下载管理器发布系统通知。 如果启用,下载管理器通过系统发布有关下载的通知NotificationManager 。 默认情况下,显示通知。 如果设置为false,则需要权限android.permission.DOWNLOAD_WITHOUT_NOTIFICATION。
| 参数(Parameters) | |
|---|---|
show |
boolean: whether the download manager should show a notification for this download. |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
DownloadManager.Request setTitle (CharSequence title)
设置此下载的标题,以显示在通知中(如果启用)。 如果没有标题,一旦下载开始,将根据下载文件名分配一个默认标题。
| 参数(Parameters) | |
|---|---|
title |
CharSequence
|
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |
DownloadManager.Request setVisibleInDownloadsUi (boolean isVisible)
设置此下载是否应显示在系统的下载UI中。 默认情况下为真。
| 参数(Parameters) | |
|---|---|
isVisible |
boolean: whether to display this download in the Downloads UI |
| 返回(Returns) | |
|---|---|
DownloadManager.Request |
this object |