Updating an android notification sequentially -
i building messaging application notifies users when new message comes in.
because happen several times day (or several times hour), don't want continually throw new notifications. instead, if user has not dismissed notification, update number of new messages pending (following "stacking" design guideline).
in android documentation, there example of updating notification number:
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()); ...
however, seems assume maintaining number within application , outside of notification manager / builder. host of reasons, inconvenient (and brittle) in context of application.
i know - there way read current number assigned message (the equivalent of mnotifybuilder.getnumber()) ?
follow-on question: if reading current number not possible, there way know running service if notification has been cancelled or manually dismissed user ?
you notification assigned id. can use id cancel or update same notification if hasn't been cancelled user.
straight documentation: "if notification same id has been posted application , has not yet been canceled, replaced updated information."
Comments
Post a Comment