2

I have an application that request DownloadManager to start a download.

What I want to do is launch my app when user clicks on the download notification for the download that my app requested from DownloadManager. Below is the code in BroadcastReceiver for DownloadManager broadcasts.

if (DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action))
        {
            long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
            long dlRef = getDlRef();
            if (downloadId != dlRef) {
                Log.d(Constants.TAG, "MY_DL_ID: " + dlRef + " EVENT FOR: " + downloadId);
            } else {
                Log.d(Constants.TAG, "Starting my activity");
                Intent i = new Intent(context, MyActivity.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            }
        }

How can I do that? In above code I get downloadId as 0.

Thanks,

Vinay

VinayChoudhary99
  • 846
  • 3
  • 13
  • 26
  • What do u mean? Show notification and clicking on it will launch activity? read this:[Notifications](http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CreateNotification) – Harin Apr 10 '15 at 10:36

2 Answers2

1

You want to be using:

intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS)

which returns an long array.

-2

After starting the download you can simply start your application as: Intent launchint = getPackageManager().getLaunchIntentForPackage("com.package.yourapp"); startActivity(launchint );

Saurav
  • 560
  • 4
  • 17
  • I want to launch my application from download notification that is shown when DownloadManager starts the download that my app requested. – VinayChoudhary99 Apr 10 '15 at 08:58
  • You can Create a Pending Intent though I'm not able to fully understand what you're trying to achieve. You can create a intent with the class you want to launch, create a pending intent and then setContentIntent to that pending intent. http://developer.android.com/training/notify-user/build-notification.html will help you more. – Saurav Apr 10 '15 at 09:13
  • An notification is shown when we download using DownloadManager. What I want is that when it is clicked it launches my application. The above code displays Intent action that is received when such notification is clicked. But the download ID is not available in this case. So if I issue an intent to launch an activity from here, will it launch my activity for all downloads, that i didnt start? I want to avoid using my own notification and hence my query! I hope my question is bit clear now :) – VinayChoudhary99 Apr 10 '15 at 14:47