Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ongoing notification on Android honeycomb has inconsistent behavior

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);
like image 922
Chase Avatar asked Jun 06 '11 03:06

Chase


2 Answers

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;
like image 132
twaddington Avatar answered Oct 21 '22 08:10

twaddington


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.

like image 37
ralepinski Avatar answered Oct 21 '22 06:10

ralepinski