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:
Cursor c = downloadManager.query(new DownloadManager.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
:
BroadcastReceiver onComplete = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// do something
}
};
registerReceiver(onComplete, new IntentFilter(
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.