IT. Expert System.

Android Reference

DownloadManager


android.app

Class DownloadManager



  • public class DownloadManager
    extends Object
    The download manager is a system service that handles long-running HTTP downloads. Clients may request that a URI be downloaded to a particular destination file. The download manager will conduct the download in the background, taking care of HTTP interactions and retrying downloads after failures or across connectivity changes and system reboots. Instances of this class should be obtained through Context.getSystemService(String) by passing Context.DOWNLOAD_SERVICE. Apps that request downloads through this API should register a broadcast receiver for ACTION_NOTIFICATION_CLICKED to appropriately handle when the user clicks on a running download in a notification or from the downloads UI. Note that the application must have the android.Manifest.permission#INTERNET permission to use this class.
    • Field Detail

      • COLUMN_ID

        public static final String COLUMN_ID
        An identifier for a particular download, unique across the system. Clients use this ID to make subsequent calls related to the download.
        See Also:
        Constant Field Values
      • COLUMN_TITLE

        public static final String COLUMN_TITLE
        The client-supplied title for this download. This will be displayed in system notifications. Defaults to the empty string.
        See Also:
        Constant Field Values
      • COLUMN_DESCRIPTION

        public static final String COLUMN_DESCRIPTION
        The client-supplied description of this download. This will be displayed in system notifications. Defaults to the empty string.
        See Also:
        Constant Field Values
      • COLUMN_MEDIA_TYPE

        public static final String COLUMN_MEDIA_TYPE
        Internet Media Type of the downloaded file. If no value is provided upon creation, this will initially be null and will be filled in based on the server's response once the download has started.
        See Also:
        RFC 1590, defining Media Types, Constant Field Values
      • COLUMN_TOTAL_SIZE_BYTES

        public static final String COLUMN_TOTAL_SIZE_BYTES
        Total size of the download in bytes. This will initially be -1 and will be filled in once the download starts.
        See Also:
        Constant Field Values
      • COLUMN_LOCAL_URI

        public static final String COLUMN_LOCAL_URI
        Uri where downloaded file will be stored. If a destination is supplied by client, that URI will be used here. Otherwise, the value will initially be null and will be filled in with a generated URI once the download has started.
        See Also:
        Constant Field Values
      • COLUMN_LOCAL_FILENAME

        public static final String COLUMN_LOCAL_FILENAME
        The pathname of the file where the download is stored.
        See Also:
        Constant Field Values
      • COLUMN_STATUS

        public static final String COLUMN_STATUS
        Current status of the download, as one of the STATUS_* constants.
        See Also:
        Constant Field Values
      • COLUMN_BYTES_DOWNLOADED_SO_FAR

        public static final String COLUMN_BYTES_DOWNLOADED_SO_FAR
        Number of bytes download so far.
        See Also:
        Constant Field Values
      • COLUMN_MEDIAPROVIDER_URI

        public static final String COLUMN_MEDIAPROVIDER_URI
        The URI to the corresponding entry in MediaProvider for this downloaded entry. It is used to delete the entries from MediaProvider database when it is deleted from the downloaded list.
        See Also:
        Constant Field Values
      • ERROR_UNKNOWN

        public static final int ERROR_UNKNOWN
        Value of COLUMN_ERROR_CODE when the download has completed with an error that doesn't fit under any other error code.
        See Also:
        Constant Field Values
      • ERROR_UNHANDLED_HTTP_CODE

        public static final int ERROR_UNHANDLED_HTTP_CODE
        Value of COLUMN_REASON when an HTTP code was received that download manager can't handle.
        See Also:
        Constant Field Values
      • ERROR_HTTP_DATA_ERROR

        public static final int ERROR_HTTP_DATA_ERROR
        Value of COLUMN_REASON when an error receiving or processing data occurred at the HTTP level.
        See Also:
        Constant Field Values
      • ERROR_INSUFFICIENT_SPACE

        public static final int ERROR_INSUFFICIENT_SPACE
        Value of COLUMN_REASON when there was insufficient storage space. Typically, this is because the SD card is full.
        See Also:
        Constant Field Values
      • ERROR_DEVICE_NOT_FOUND

        public static final int ERROR_DEVICE_NOT_FOUND
        Value of COLUMN_REASON when no external storage device was found. Typically, this is because the SD card is not mounted.
        See Also:
        Constant Field Values
      • ERROR_CANNOT_RESUME

        public static final int ERROR_CANNOT_RESUME
        Value of COLUMN_REASON when some possibly transient error occurred but we can't resume the download.
        See Also:
        Constant Field Values
      • ERROR_FILE_ALREADY_EXISTS

        public static final int ERROR_FILE_ALREADY_EXISTS
        Value of COLUMN_REASON when the requested destination file already exists (the download manager will not overwrite an existing file).
        See Also:
        Constant Field Values
      • PAUSED_WAITING_TO_RETRY

        public static final int PAUSED_WAITING_TO_RETRY
        Value of COLUMN_REASON when the download is paused because some network error occurred and the download manager is waiting before retrying the request.
        See Also:
        Constant Field Values
      • PAUSED_WAITING_FOR_NETWORK

        public static final int PAUSED_WAITING_FOR_NETWORK
        Value of COLUMN_REASON when the download is waiting for network connectivity to proceed.
        See Also:
        Constant Field Values
      • PAUSED_QUEUED_FOR_WIFI

        public static final int PAUSED_QUEUED_FOR_WIFI
        Value of COLUMN_REASON when the download exceeds a size limit for downloads over the mobile network and the download manager is waiting for a Wi-Fi connection to proceed.
        See Also:
        Constant Field Values
      • ACTION_DOWNLOAD_COMPLETE

        public static final String ACTION_DOWNLOAD_COMPLETE
        Broadcast intent action sent by the download manager when a download completes.
        See Also:
        Constant Field Values
      • ACTION_NOTIFICATION_CLICKED

        public static final String ACTION_NOTIFICATION_CLICKED
        Broadcast intent action sent by the download manager when the user clicks on a running download, either from a system notification or from the downloads UI.
        See Also:
        Constant Field Values
      • ACTION_VIEW_DOWNLOADS

        public static final String ACTION_VIEW_DOWNLOADS
        Intent action to launch an activity to display all downloads.
        See Also:
        Constant Field Values
      • EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS

        public static final String EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS
        When clicks on multiple notifications are received, the following provides an array of download ids corresponding to the download notification that was clicked. It can be retrieved by the receiver of this Intent using Intent.getLongArrayExtra(String).
        See Also:
        Constant Field Values
      • UNDERLYING_COLUMNS

        public static final String[] UNDERLYING_COLUMNS
        columns to request from DownloadProvider.
    • Method Detail

      • setAccessAllDownloads

        public void setAccessAllDownloads(boolean accessAllDownloads)
        Makes this object access the download provider through /all_downloads URIs rather than /my_downloads URIs, for clients that have permission to do so.
      • enqueue

        public long enqueue(DownloadManager.Request request)
        Enqueue a new download. The download will start automatically once the download manager is ready to execute it and connectivity is available.
        Parameters:
        request - the parameters specifying this download
        Returns:
        an ID for the download, unique across the system. This ID is used to make future calls related to this download.
      • markRowDeleted

        public int markRowDeleted(long... ids)
        Marks the specified download as 'to be deleted'. This is done when a completed download is to be removed but the row was stored without enough info to delete the corresponding metadata from Mediaprovider database. Actual cleanup of this row is done in DownloadService.
        Parameters:
        ids - the IDs of the downloads to be marked 'deleted'
        Returns:
        the number of downloads actually updated
      • remove

        public int remove(long... ids)
        Cancel downloads and remove them from the download manager. Each download will be stopped if it was running, and it will no longer be accessible through the download manager. If there is a downloaded file, partial or complete, it is deleted.
        Parameters:
        ids - the IDs of the downloads to remove
        Returns:
        the number of downloads actually removed
      • query

        public Cursor query(DownloadManager.Query query)
        Query the download manager about downloads that have been requested.
        Parameters:
        query - parameters specifying filters for this query
        Returns:
        a Cursor over the result set of downloads, with columns consisting of all the COLUMN_* constants.
      • getUriForDownloadedFile

        public Uri getUriForDownloadedFile(long id)
        Returns Uri for the given downloaded file id, if the file is downloaded successfully. otherwise, null is returned.

        If the specified downloaded file is in external storage (for example, /sdcard dir), then it is assumed to be safe for anyone to read and the returned Uri corresponds to the filepath on sdcard.

        Parameters:
        id - the id of the downloaded file.
        Returns:
        the Uri for the given downloaded file id, if download was successful. null otherwise.
      • getMimeTypeForDownloadedFile

        public String getMimeTypeForDownloadedFile(long id)
        Returns Uri for the given downloaded file id, if the file is downloaded successfully. otherwise, null is returned.

        If the specified downloaded file is in external storage (for example, /sdcard dir), then it is assumed to be safe for anyone to read and the returned Uri corresponds to the filepath on sdcard.

        Parameters:
        id - the id of the downloaded file.
        Returns:
        the Uri for the given downloaded file id, if download was successful. null otherwise.
      • restartDownload

        public void restartDownload(long... ids)
        Restart the given downloads, which must have already completed (successfully or not). This method will only work when called from within the download manager's process.
        Parameters:
        ids - the IDs of the downloads
      • getMaxBytesOverMobile

        public static Long getMaxBytesOverMobile(Context context)
        Returns maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no limit
        Parameters:
        context - the Context to use for accessing the ContentResolver
        Returns:
        maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no limit
      • getRecommendedMaxBytesOverMobile

        public static Long getRecommendedMaxBytesOverMobile(Context context)
        Returns recommended maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no recommended limit. The user will have the option to bypass this limit.
        Parameters:
        context - the Context to use for accessing the ContentResolver
        Returns:
        recommended maximum size, in bytes, of downloads that may go over a mobile connection; or null if there's no recommended limit.
      • isActiveNetworkExpensive

        public static boolean isActiveNetworkExpensive(Context context)
      • getActiveNetworkWarningBytes

        public static long getActiveNetworkWarningBytes(Context context)
      • addCompletedDownload

        public long addCompletedDownload(String title,
                                String description,
                                boolean isMediaScannerScannable,
                                String mimeType,
                                String path,
                                long length,
                                boolean showNotification)
        Adds a file to the downloads database system, so it could appear in Downloads App (and thus become eligible for management by the Downloads App).

        It is helpful to make the file scannable by MediaScanner by setting the param isMediaScannerScannable to true. It makes the file visible in media managing applications such as Gallery App, which could be a useful purpose of using this API.

        Parameters:
        title - the title that would appear for this file in Downloads App.
        description - the description that would appear for this file in Downloads App.
        isMediaScannerScannable - true if the file is to be scanned by MediaScanner. Files scanned by MediaScanner appear in the applications used to view media (for example, Gallery app).
        mimeType - mimetype of the file.
        path - absolute pathname to the file. The file should be world-readable, so that it can be managed by the Downloads App and any other app that is used to read it (for example, Gallery app to display the file, if the file contents represent a video/image).
        length - length of the downloaded file
        showNotification - true if a notification is to be sent, false otherwise
        Returns:
        an ID for the download entry added to the downloads app, unique across the system This ID is used to make future calls related to this download.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 384 / . Delta: 0.03331 с