Skip to content Skip to sidebar Skip to footer

Check If Downloads Are Active

So I'm using Download Manager to download multiple files in my app. I need these files to finish downloading before starting a certain activity. How can I check if there are active

Solution 1:

Use query() to inquire about downloads. When you call enqueue(), the return value is an ID for the download. You can query by status as well:

Cursorc= downloadManager.query(newDownloadManager.Query()
        .setFilterByStatus(DownloadManager.STATUS_PAUSED
                | DownloadManager.STATUS_PENDING
                | DownloadManager.STATUS_RUNNING));

To be notified when a download is finished, register a BroadcastReceiver for ACTION_DOWNLOAD_COMPLETE:

BroadcastReceiveronComplete=newBroadcastReceiver() {
    @OverridepublicvoidonReceive(Context context, Intent intent) {
        // do something
    }
};

registerReceiver(onComplete, newIntentFilter(
        DownloadManager.ACTION_DOWNLOAD_COMPLETE));

Note that you should also listen for the ACTION_NOTIFICATION_CLICKED broadcast to know when a user has clicked the notification for a running download.

Post a Comment for "Check If Downloads Are Active"