Android Notification Action to Start service, intent extra not included -
i have notification has 2 actions, accept , decline, , pendingintent start service, requestupdaterservice. put extras intent pendingintent gets made (via pendingintent#getservice). problem when service started, extras aren't in intent passed service#onstartcommand.
notification issuer:
notificationcompat.builder n = new notificationcompat.builder(context) .setdefaults(notification.default_all) .setsmallicon(r.drawable.logo_small) .setcontenttitle(notification.gettext()) .setcontenttext(context.getstring(r.string.app_name)) .setcontentintent(getopenapppendingintent()) .setongoing(false) .setstyle(new notificationcompat.bigtextstyle().bigtext(text)); intent actionaccept = new intent(context, updaterequestupdater.class); actionaccept.putextra(keysandcodes.update_request_id, notificationrequestid); actionaccept.putextra(keysandcodes.update_request_notification_id, notificationid); actionaccept.setaction(keysandcodes.update_request_updater_accept); pendingintent acceptpendingintent = pendingintent.getservice(context, 0, actionaccept, 0); intent actiondecline = new intent(context, requestupdater.class); actiondecline.putextra(keysandcodes.update_request_id, notificationrequestid); actiondecline.putextra(keysandcodes.update_request_notification_id, notificationid); actiondecline.setaction(keysandcodes.update_request_updater_decline); pendingintent declinependingintent = pendingintent.getservice(context, 0, actiondecline, 0); n.addaction(r.drawable.ic_action_accept, getstring(r.string.accept_request), acceptpendingintent); n.addaction(r.drawable.ic_action_cancel, getstring(r.string.decline_request), declinependingintent); notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service); notificationmanager.notify(notification.getid(), n.build()); requestupdaterservice.java
@override public int onstartcommand(intent intent, int flags, int startid) { integer requestid = intent.getintextra(keysandcodes.update_request_id, 0); integer notificationid = intent.getintextra(keysandcodes.update_request_notification_id, 0); ... } whenever requestupdaterservice started requestid , notificationid 0. doing wrong?
try changing line:
pendingintent acceptpendingintent = pendingintent.getservice(context, 0, actionaccept, 0); to this:
pendingintent acceptpendingintent = pendingintent.getservice(context, 0, actionaccept, pendingintent.flag_update_current);
Comments
Post a Comment