Android: Multiple Notifications as single list in Status Bar -
i trying notify
user based on criteria. multiple notifications
being shown in status bar
want group notification in single notification
, when user clicks in status bar
, want retrieve notifications in group. possible? or have maintain pendingintents
of notifications? appreciated. example, if birthdays of 2 friends come on same day, 2 notifications should shown. want combine these notifications i.e. instead of 2 notifications in status bar, want one, when user clicks on it, should have information 2 notifications. possible?
please see code below displaying notifications.
public void displaynotification(birthdaydetail detail) { notificationcompat.builder builder = new notificationcompat.builder(this.context); builder.setsmallicon(r.drawable.ic_launcher); builder.setcontenttitle(detail.getcontactname()); builder.setcontenttext(detail.getcontactbirthdate()); intent resultintent = new intent(this.context, notificationview.class); resultintent.putextra("name", detail.getcontactname()); resultintent.putextra("birthdate", detail.getcontactbdate()); resultintent.putextra("picture_path", detail.getpicturepath()); resultintent.putextra("iscontact", detail.isfromcontact()); resultintent.putextra("notificationid", notificationid); if(detail.isfromcontact()) { resultintent.putextra("phone_number", detail.getphonenumber()); } pendingintent resultpendingintent = pendingintent.getactivity(this.context, requestcode++, resultintent, pendingintent.flag_update_current); builder.setcontentintent(resultpendingintent); notificationmanager = (notificationmanager) this.context.getsystemservice(context.notification_service); notificationmanager.notify(notificationid, builder.build()); notificationid++; }
when need issue notification multiple times same type of event, should avoid making new notification. instead, should consider updating previous notification, either changing of values or adding it, or both.
you can use like:
mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); // sets id notification, can updated int notifyid = 1; mnotifybuilder = new notificationcompat.builder(this) .setcontenttitle("new message") .setcontenttext("you've received new messages.") .setsmallicon(r.drawable.ic_notify_status) nummessages = 0; // start of loop processes data , notifies user ... mnotifybuilder.setcontenttext(currenttext) .setnumber(++nummessages); // because id remains unchanged, existing notification // updated. mnotificationmanager.notify( notifyid, mnotifybuilder.build());
source: http://developer.android.com/training/notify-user/managing.html
Comments
Post a Comment