Search code examples
androidnotificationsandroid-c2dm

How can I dynamically change the Notification message when I aggregate multiple notifications in Android?


I'm trying to perform this simple task dealing with push notifications in Android (C2DM):

  • if no notification exists in the notification bar, set it to "foo A"
  • if a notification already exists, grab it, read its text, and then update it to something like "N notifications: foo, bar, ...". This is similar to what the gmail client would do on Android when you get 1 email vs multiple ones

I have looked through the docs, read http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating, searched SO and the web, but so far, I don't see a way to get access to the notification currently in the notification bar.

Do I need to manage the count elsewhere and have it reset when the user dismisses the notification? Is there no way to read the existing one?

Thank you.


Solution

  • if a notification already exists, grab it, read its text, and then update it to something like "N notifications: foo, bar, ...". This is similar to what the gmail client would do on Android when you get 1 email vs multiple ones

    No, it isn't. Gmail already has this information in a database. It does not need to "grab [a notification], read its text".

    Moreover, what you want is impossible.

    Do I need to manage the count elsewhere and have it reset when the user dismisses the notification?

    Yes.

    Is there no way to read the existing one?

    No.