I am using notifications in my Android application. Whenever i receive a notification, i am trying to increment the number of unread notifications using notification.number as in the code below.
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
"A new notification", System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.number += 1;
Intent intent = new Intent(this, NotificationReceiver.class);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "This is the title",
"This is the text", activity);
notificationManager.notify(0, notification);
But, no matter how many notifications i receive, the counter is not incrementing. Its always displaying 1 only. I am not getting what is wrong here. Could anybody help me…?
The problem is, you are creating a new notification object. just create once, check if it exists in field