10

You know what I'm talking about: for example when you get multiple new emails the notification icon in the status bar is augmented with a little red circle that contains number of unread mails. Twitroid has the same icon. Any idea how it's done? I don't think (or so I hope) there are 10000 similar icons. Is this red circle generated and overlaid the notification icon? If so - any code snippets will be much appreciated.

2 Answers 2

19

This one is nice and easy, just change Notification.number to whatever number you want to appear on your Notification, e.g.:

Notification notification = new Notification(icon, tickerText, when); notification.number = 4; 
Sign up to request clarification or add additional context in comments.

3 Comments

Awesome! Thanks! Stupid me didn't even considered that this may be already built in
Is this still available in 4.2 jelly bean?. I know they have changed the AOSP code lot and added into expanded view but can we still show the icon with number on status bar ? Any idea ?
@user755499 - No. Here's a quote from the API docs: "The number of events that this notification represents. For example, in a new mail notification, this could be the number of unread messages. The system may or may not use this field to modify the appearance of the notification. For example, before HONEYCOMB, this number was superimposed over the icon in the status bar. Starting with HONEYCOMB, the template used by Notification.Builder has displayed the number in the expanded notification view. If the number is 0 or negative, it is never shown."
0

A good example of how to use the notification bar can be found in this tutorial:

http://www.firstdroid.com/2010/05/09/learn-by-example-using-notification-bar/

Hope it helps, Adrian.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.