Thursday 15 August 2013

android - Update InboxStyle Notifications with a new line -



android - Update InboxStyle Notifications with a new line -

i'm trying implement inboxstyle notification on app create people see lastly notifications, can't find way update lastly notification, overwrites new 1 if utilize same notif_id.

my actual code:

private void sendnotification(string notif, string[] args) { notificationmanager mnotificationmanager = (notificationmanager) this.getsystemservice(context.notification_service); pendingintent contentintent = pendingintent.getactivity(this, 0, new intent(this, main_activity.class), 0); if (notif.equals("notif_0")){ notif = string.format(getstring(r.string.notif_0), args[0]); } else if (notif.equals("notif_1")) { notif = string.format(getstring(r.string.notif_1), args[0]); } else if (notif.equals("notif_2")) { notif = string.format(getstring(r.string.notif_2), args[0]); } else if (notif.equals("notif_2_ex")) { notif = string.format(getstring(r.string.notif_2_ex), args[0], args[1], args[2]); } else if (notif.equals("notif_3")) { notif = string.format(getstring(r.string.notif_3), args[0]); } else if (notif.equals("notif_3_ex")) { notif = string.format(getstring(r.string.notif_3_ex), args[0], args[1], args[2]); } else if (notif.equals("notif_3_ex_dis")) { notif = string.format(getstring(r.string.notif_3_ex_dis), args[0], args[1], args[2]); } else if (notif.equals("notif_4")) { notif = string.format(getstring(r.string.notif_4), args[0]); } else if (notif.equals("notif_5")) { notif = string.format(getstring(r.string.notif_5), args[0]); } else if (notif.equals("notif_5_ex")) { notif = string.format(getstring(r.string.notif_5_ex), args[0], args[1], args[2]); } else if (notif.equals("notif_6_ex")) { notif = string.format(getstring(r.string.notif_6_ex), args[0], args[1]); } else if (notif.equals("notif_31")) { notif = string.format(getstring(r.string.notif_31), args[0]); } notificationcompat.inboxstyle inboxstyle = new notificationcompat.inboxstyle(); inboxstyle.addline(notif); notificationcompat.builder mbuilder = new notificationcompat.builder(this) .setsmallicon(r.drawable.ic_launcher) .setautocancel(true) .setcontenttitle(getstring(r.string.app_name)) .setcontenttext(notif); mbuilder.setstyle(inboxstyle); mbuilder.setcontentintent(contentintent); notification notification = mbuilder.build(); notification.flags |= notification.flag_auto_cancel; notification.flags |= notification.flag_show_lights; notification.defaults |= notification.default_sound; notification.defaults |= notification.default_lights; notification.defaults |= notification.default_vibrate; notification.ledargb = 0xff00ff00; notification.ledonms = 300; notification.ledoffms = 1000; notification.flags |= notification.flag_show_lights; mnotificationmanager.notify(1, notification); }

extra questions: there way display lastly 5 notifications (the new 1 , 4 newer lastly notification)? i'm searching way display bigview instead of inboxstyle, when there's 1 notification active, otherwise notification should displayed list, possible see if notification same id nowadays , load 1 or style based on check? can't find info on internet.

managed in ugly way now. save lastly notifications in sqlite db, retrieve them time , build updated notification. clean db when launch app next time user have new notification.

i don't know if best solution, can't find api access old notification retrieve info implemented solution.

android notifications android-notifications

No comments:

Post a Comment