9

I have an ongoing notification for downloading files in the background. I have been successful in creating an multiple simultaneous updating progress bar notifications that are also able to be canceled. This works fine on all tested devices except for some of the more recent Android tablets with Honeycomb.

The effect is now that the original notification message is constantly redisplayed, preventing the user from clicking on the clock to bring up the list of ongoing notifications. As such, no progress bars are even seen. Has anyone been successful in essentially creating progress bar notifications on Honeycomb?

As a side, I also find that my black notification text is no longer readable with the black background of the notification list. Is there a way to set white text for Honeycomb devices?

Note: This has been tested on the Optimus Pad L-06C running Android 3.0.1 and the Motorola Xoom

Below is a the notification creation

// Create new notification for downloading
mNotification = new Notification(R.drawable.owl_icon, getNotificationText(R.string.notification_content_downloading), 0);
mNotification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT);

// Create custom progress bar view
RemoteViews contentView = new RemoteViews(CourseSyncService.this.getPackageName(), R.layout.notification_downloading);
contentView.setTextViewText(R.id.notificationTitle, mCourseTitle);
contentView.setProgressBar(R.id.notificationProgressBar, 100, 0, false);
contentView.setTextViewText(R.id.notificationPercentage, "0%");
mNotification.contentView = contentView;

// Create pending intent for the notification
Intent notificationIntent = new Intent(CourseSyncService.this, CancelDownloadActivity.class);
notificationIntent.putExtra(CourseSyncService.KEY_USER_ID, mUserId);
notificationIntent.putExtra(CourseSyncService.KEY_COURSE_ID, mCourseId);
notificationIntent.putExtra(CourseSyncService.KEY_COURSE_TITLE, mCourseTitle);
PendingIntent contentIntent = PendingIntent.getActivity(CourseSyncService.this, mCourseId, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
mNotification.contentIntent = contentIntent;

// Launch notification
mNotificationManager.notify(mCourseId, mNotification);

And here is how I update the notification:

// Update the progress bar of the notification view 
mNotification.contentView.setProgressBar(R.id.notificationProgressBar, mItemCount, mProgressCount, false);
mNotification.contentView.setTextViewText(R.id.notificationPercentage, String.valueOf(mProgress) + "%");
mNotificationManager.notify(mCourseId, mNotification);
Chase
  • 11,161
  • 8
  • 42
  • 39
  • 1
    notify(id, notification) has docs stating that on a same id the notification "will be replaced by the updated information." Seems Honeycomb adds a horrid redisplay which on previous versions didnt occur. – Rene Aug 07 '11 at 19:19
  • 1
    Congrats on going over 1500! My vote pushed you over the edge...But mostly thanks for asking this problem I had the same issue and this fixed it. – JPM Mar 22 '12 at 22:53

4 Answers4

7

To fix this problem you need to set the bitwise Notification.FLAG_ONLY_ALERT_ONCE on your ongoing notification. This will ensure that the user is only ever notified when the notification is first displayed. Following that, they will have to open the notification tray to view the status of the notification.

Notification notification = new Notification();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
twaddington
  • 11,607
  • 5
  • 35
  • 46
  • You are my hero! The comments on this flag reads "Bit to be bitwise-ored into the flags field that should be set if you want the sound and/or vibration play each time the notification is sent, even if it has not been canceled before that." so that may be why I never tried using it. Thanks! – Chase Aug 26 '11 at 08:11
1

I think I found the issue to this if anyone is still looking. The problem is when you create a new notification, the when is set to the current system time. If you take a look at: http://developer.android.com/reference/android/app/Notification.html#when you will read that a download operation when should be stamped at the start. If you don't (like I was doing) and you have multiple download notifications, they will continue to reorder themselves based on the when field.

ralepinski
  • 1,756
  • 8
  • 15
0

To solve this (on 4.0.3,did not try on previous API levels) I had to keep a reference to my Notification, update it every time something changed, and then send the same Notification object to NotificationManager.notify().

Altough I was setting the flags as specified in @twaddingtion's answer, and sending the same id to the NotificationManager my notification were getting messed up in the SystemBar.

Ovidiu Latcu
  • 71,607
  • 15
  • 76
  • 84
0

The notification list does not have a black background on GB; only the status bar was changed to black. What device is causing the trouble? Have you tried this on the standard GB to make sure this is not a problem specific to that device instead of something that changed in the platform? Do you know if this device is even something that is compatible with the CDD and passed CTS?

hackbod
  • 90,665
  • 16
  • 140
  • 154
  • I knew I should have mentioned the model. I am currently working with the Optimus Pad L-06C running Android 3.0.1. I have not tested with any other devices but will as soon as I get my hands on one. I am not familiar whether this device meets CDD standards or not. I will update the question with the relevant info. Thanks. – Chase Jun 06 '11 at 05:55
  • Also, I mistakenly put Gingerbread when I meant Honeycomb. And I have now verified this on two devices. – Chase Jun 08 '11 at 09:57
  • 1
    Ah yes as part of the new UI in Android 3.0 the background changed. This answer on stack overflow should help: http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors – hackbod Jun 23 '11 at 16:33
  • But did you had solved your first problem of multiple ongoing notification? – CeccoCQ Jul 21 '11 at 07:29