开发者

Android Notification Bar Number

I've been able to successfully display the notification number count on the Android emulator. However, it doesn't display anything when I use it on an actual Andro开发者_StackOverflow社区id phone. Any suggestions on why there might be a difference?


Try first setting it up with the number 1, then go higher. Suggestion from here: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

number field

This value indicates the current number of events represented by the notification. The appropriate number is overlaid on top of the status bar icon. If you intend to use this field, then you must start with "1" when the Notification is first created. (If you change the value from zero to anything greater during an update, the number is not shown.)


In my case it was something with the phone. It was a Droid Incredible. It didn't work with android 2.1, but Verizon's release of 2.2 fixed the issue.


(for posterity)

To elaborate on what Izkata said, if you put up a notification with no "number" count and you want to then add the number, you need to cancel the existing notification and remake it with the number field set. ("cancel" is one of the NotificationManager methods.) Going from 0 to a number will not display the number unless you cancel the original notification.

Similarly, if you have a notification up with a number on it and want to go back to a blank notification, you need to cancel the current one and remake it with no number. Going from a number to 0 will just show the little green bubble with nothing in it.

Note that if you just want to change an existing number, you can just re-issue the notification with the new number -- no need to cancel the previous one.


      Take two global variable count, i;
         public void createNotification(View view){



NotificationManager mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.logo,
        "A new notification", System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(this,SampleJsonReadingActivity.class);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "This is the title",
        "This is the text", activity);
if(count==1){
    count ++;
}
    else{
         i++;

    }
notification.number +=i;
mNotificationManager.notify(0, notification);

}

it works for me....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜