giozh
giozh

Reputation: 10068

DownloadManager: notify when a download is finished

I've wrote a code to use a DownloadManager in order to download some files. Now I want to do the following:

  1. Notify my activity when a download is finished (and which download is finished)
  2. Receive periodical information about specific file's download progress (like happens in the play store, where the download progress is shown inside DownloadManager notification bar and inside google play current page)

Upvotes: 3

Views: 7057

Answers (1)

Misagh Emamverdi
Misagh Emamverdi

Reputation: 3674

To receive a notification when the download is completed, register a Receiver to receive an ACTION_DOWNLOAD_COMPLETE broadcast. It will include an EXTRA_DOWNLOAD_ID extra that contains the reference ID of the download that has completed.

IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        long reference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
        if (myDownloadReference == reference) {
            // Do something with downloaded file.
       }
    }
};
registerReceiver(receiver, filter);

Upvotes: 9

Related Questions