Fix download notification click behaviour.
Danny Baumann [Wed, 3 Apr 2013 12:36:21 +0000 (14:36 +0200)]
PendingIntent.getBroadcast() doesn't update the intent extras if not
explicitly given something to distinguish the intents. This caused the
notification on-click to do nothing on everything but the first
download.

Change-Id: I29544ae5b04f8304cbbe720066a26ff90e422107

src/com/android/providers/downloads/DownloadNotifier.java

index daae783..f387865 100644 (file)
@@ -126,11 +126,14 @@ public class DownloadNotifier {
 
             // Build action intents
             if (type == TYPE_ACTIVE || type == TYPE_WAITING) {
+                // build a synthetic uri for intent identification purposes
+                final Uri uri = new Uri.Builder().scheme("active-dl").appendPath(tag).build();
                 final Intent intent = new Intent(Constants.ACTION_LIST,
-                        null, mContext, DownloadReceiver.class);
+                        uri, mContext, DownloadReceiver.class);
                 intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS,
                         getDownloadIds(cluster));
-                builder.setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0));
+                builder.setContentIntent(PendingIntent.getBroadcast(mContext,
+                        0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
                 builder.setOngoing(true);
 
             } else if (type == TYPE_COMPLETE) {
@@ -152,7 +155,8 @@ public class DownloadNotifier {
                 final Intent intent = new Intent(action, uri, mContext, DownloadReceiver.class);
                 intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS,
                         getDownloadIds(cluster));
-                builder.setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0));
+                builder.setContentIntent(PendingIntent.getBroadcast(mContext,
+                        0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
 
                 final Intent hideIntent = new Intent(Constants.ACTION_HIDE,
                         uri, mContext, DownloadReceiver.class);