Android – How to launch download manager from Broadcast Receiver

android

My application downloads large zip files (100mb+). I'm using the default DownloadManager to facilitate the download. The Google API docs suggest to register a BroadcastReceiver and listen for ACTION_NOTIFICATION_CLICKED. I'm doing that, but I have no clue how to call the DownloadManager from within the BroadcastReceiver.

What I want to do is basically what the browser does. When the browser downloads a file and the user clicks on the DownloadManager notification the DownloadManager window pops up. What intent do I use to accomplish this?

My Code:

<receiver android:name="com.test.receiver.DownloadReceiver">
  <intent-filter>
     <action android:name="android.intent.action.DOWNLOAD_COMPLETE"></action>
     <action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED" />
  </intent-filter>
</receiver>

public class DownloadReceiver extends BroadcastReceiver {

private static final String tag = DownloadReceiver.class.getSimpleName();

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
    *** code for unzipping removed ***
    }
    else if (DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) {
        // Open the download manager
        // BUT HOW???

    }

Best Answer

Found my own answer. This does the trick.

Intent dm = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
dm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(dm);
Related Topic