public static class DownloadManager.Request extends Object
setDestinationUri(Uri)
.Modifier and Type | Field and Description |
---|---|
static int |
NETWORK_BLUETOOTH
Deprecated.
|
static int |
NETWORK_MOBILE
Bit flag for
setAllowedNetworkTypes(int) corresponding to
ConnectivityManager.TYPE_MOBILE . |
static int |
NETWORK_WIFI
Bit flag for
setAllowedNetworkTypes(int) corresponding to
ConnectivityManager.TYPE_WIFI . |
static int |
VISIBILITY_HIDDEN
This download doesn't show in the UI or in the notifications.
|
static int |
VISIBILITY_VISIBLE
This download is visible but only shows in the notifications
while it's in progress.
|
static int |
VISIBILITY_VISIBLE_NOTIFY_COMPLETED
This download is visible and shows in the notifications while
in progress and after completion.
|
static int |
VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION
This download shows in the notifications after completion ONLY.
|
Modifier and Type | Method and Description |
---|---|
DownloadManager.Request |
addRequestHeader(String header,
String value)
Add an HTTP header to be included with the download request.
|
void |
allowScanningByMediaScanner()
If the file to be downloaded is to be scanned by MediaScanner, this method
should be called before
DownloadManager.enqueue(Request) is called. |
DownloadManager.Request |
setAllowedNetworkTypes(int flags)
Restrict the types of networks over which this download may proceed.
|
DownloadManager.Request |
setAllowedOverMetered(boolean allow)
Set whether this download may proceed over a metered network
connection.
|
DownloadManager.Request |
setAllowedOverRoaming(boolean allowed)
Set whether this download may proceed over a roaming connection.
|
DownloadManager.Request |
setDescription(CharSequence description)
Set a description of this download, to be displayed in notifications (if enabled)
|
DownloadManager.Request |
setDestinationInExternalFilesDir(Context context,
String dirType,
String subPath)
Set the local destination for the downloaded file to a path within
the application's external files directory (as returned by
Context.getExternalFilesDir(String) . |
DownloadManager.Request |
setDestinationInExternalPublicDir(String dirType,
String subPath)
Set the local destination for the downloaded file to a path within
the public external storage directory (as returned by
Environment.getExternalStoragePublicDirectory(String) ). |
DownloadManager.Request |
setDestinationToSystemCache()
Set the local destination for the downloaded file to the system cache dir (/cache).
|
DownloadManager.Request |
setDestinationUri(Uri uri)
Set the local destination for the downloaded file.
|
DownloadManager.Request |
setMimeType(String mimeType)
Set the MIME content type of this download.
|
DownloadManager.Request |
setNotificationVisibility(int visibility)
Control whether a system notification is posted by the download manager while this
download is running or when it is completed.
|
DownloadManager.Request |
setRequiresCharging(boolean requiresCharging)
Specify that to run this download, the device needs to be plugged in.
|
DownloadManager.Request |
setRequiresDeviceIdle(boolean requiresDeviceIdle)
Specify that to run, the download needs the device to be in idle
mode.
|
DownloadManager.Request |
setShowRunningNotification(boolean show)
Deprecated.
|
DownloadManager.Request |
setTitle(CharSequence title)
Set the title of this download, to be displayed in notifications (if enabled).
|
DownloadManager.Request |
setVisibleInDownloadsUi(boolean isVisible)
Set whether this download should be displayed in the system's Downloads UI.
|
public static final int NETWORK_MOBILE
setAllowedNetworkTypes(int)
corresponding to
ConnectivityManager.TYPE_MOBILE
.public static final int NETWORK_WIFI
setAllowedNetworkTypes(int)
corresponding to
ConnectivityManager.TYPE_WIFI
.@Deprecated public static final int NETWORK_BLUETOOTH
setAllowedNetworkTypes(int)
corresponding to
ConnectivityManager.TYPE_BLUETOOTH
.public static final int VISIBILITY_VISIBLE
public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED
public static final int VISIBILITY_HIDDEN
public static final int VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION
DownloadManager.addCompletedDownload(String, String,
boolean, String, String, long, boolean)
.public Request(Uri uri)
uri
- the HTTP or HTTPS URI to download.public DownloadManager.Request setDestinationUri(Uri uri)
The downloaded file is not scanned by MediaScanner.
But it can be made scannable by calling allowScanningByMediaScanner()
.
By default, downloads are saved to a generated filename in the shared download cache and may be deleted by the system at any time to reclaim space.
public DownloadManager.Request setDestinationToSystemCache()
android.Manifest.permission#ACCESS_CACHE_FILESYSTEM
.
The downloaded file is not scanned by MediaScanner.
But it can be made scannable by calling allowScanningByMediaScanner()
.
Files downloaded to /cache may be deleted by the system at any time to reclaim space.
public DownloadManager.Request setDestinationInExternalFilesDir(Context context, String dirType, String subPath)
Context.getExternalFilesDir(String)
.
The downloaded file is not scanned by MediaScanner. But it can be
made scannable by calling allowScanningByMediaScanner()
.
context
- the Context
to use in determining the external
files directorydirType
- the directory type to pass to
Context.getExternalFilesDir(String)
subPath
- the path within the external directory, including the
destination filenameIllegalStateException
- If the external storage directory
cannot be found or created.public DownloadManager.Request setDestinationInExternalPublicDir(String dirType, String subPath)
Environment.getExternalStoragePublicDirectory(String)
).
The downloaded file is not scanned by MediaScanner. But it can be
made scannable by calling allowScanningByMediaScanner()
.
dirType
- the directory type to pass to Environment.getExternalStoragePublicDirectory(String)
subPath
- the path within the external directory, including the
destination filenameIllegalStateException
- If the external storage directory
cannot be found or created.public void allowScanningByMediaScanner()
DownloadManager.enqueue(Request)
is called.public DownloadManager.Request addRequestHeader(String header, String value)
header
- HTTP header namevalue
- header valuepublic DownloadManager.Request setTitle(CharSequence title)
public DownloadManager.Request setDescription(CharSequence description)
public DownloadManager.Request setMimeType(String mimeType)
@Deprecated public DownloadManager.Request setShowRunningNotification(boolean show)
setNotificationVisibility(int)
NotificationManager
. By default, a notification is
shown.
If set to false, this requires the permission
android.permission.DOWNLOAD_WITHOUT_NOTIFICATION.show
- whether the download manager should show a notification for this download.public DownloadManager.Request setNotificationVisibility(int visibility)
NotificationManager
.
By default, a notification is shown only when the download is in progress.
It can take the following values: VISIBILITY_HIDDEN
,
VISIBILITY_VISIBLE
,
VISIBILITY_VISIBLE_NOTIFY_COMPLETED
.
If set to VISIBILITY_HIDDEN
, this requires the permission
android.permission.DOWNLOAD_WITHOUT_NOTIFICATION.
visibility
- the visibility setting valuepublic DownloadManager.Request setAllowedNetworkTypes(int flags)
setAllowedOverMetered(boolean)
instead, since it's more
flexible.
As of Build.VERSION_CODES.N
, setting only the
NETWORK_WIFI
flag here is equivalent to calling
setAllowedOverMetered(boolean)
with false
.
flags
- any combination of the NETWORK_* bit flags.public DownloadManager.Request setAllowedOverRoaming(boolean allowed)
allowed
- whether to allow a roaming connection to be usedpublic DownloadManager.Request setAllowedOverMetered(boolean allow)
public DownloadManager.Request setRequiresCharging(boolean requiresCharging)
requiresCharging
- Whether or not the device is plugged in.JobInfo.Builder.setRequiresCharging(boolean)
public DownloadManager.Request setRequiresDeviceIdle(boolean requiresDeviceIdle)
Idle mode is a loose definition provided by the system, which means that the device is not in use, and has not been in use for some time.
requiresDeviceIdle
- Whether or not the device need be within an
idle maintenance window.JobInfo.Builder.setRequiresDeviceIdle(boolean)
public DownloadManager.Request setVisibleInDownloadsUi(boolean isVisible)
isVisible
- whether to display this download in the Downloads UI