Android: Click event for Status bar notification -
i've got following code create status bar notification:
public void txtnotification(int id, string msg){ notificationmanager manager = (notificationmanager) getsystemservice(context.notification_service); notification notification = new notification(android.r.drawable.sym_action_email, msg, system.currenttimemillis()); // pendingintent launch activity if user selects notification intent intent = new intent(this, mainactivity.class) intent.putextra("yourpackage.notifyid", id); pendingintent contentintent = pendingintent.getactivity(this, 1, intent, 0); notification.setlatesteventinfo(this, "title", msg, contentintent); manager.notify(id, notification); } when notification clicked, want call method, preferrably access id of notification.
thanks in advance,
tim
(edit: updated code after reading first answer, still don't know how listen intent)
i think best way handle click on notification (maybe way?) define method within class pendingintent calls (mainactivity in case). can modify intent before passing getactivity() include id of notification:
// pendingintent launch activity if user selects notification intent intent = new intent(this, mainactivity.class) intent.putextra("yourpackage.notifyid", id); pendingintent contentintent = pendingintent.getactivity(this, 1, intent, 0); then watch intent within mainactivity , call method defined within class handle notification. can extract id incoming intent.
update:
in order activity handle notification, you'll need first define activity in androidmanifest.xml file, including intent filters need. in activity's onstart() can extract extras incoming intent, , act upon data. high level overview, suggest read parts of dev guide familiarize concepts. following page place start:
http://developer.android.com/guide/topics/fundamentals.html
also "yourpackage" should replaced name of package includes class, such "com.project.foo".
Comments
Post a Comment