android - custom notification button click -
in application have notification show.
let's when notification show want press 'yes' go activity , hide notification, press 'no' nothing hide notification.
i tried code instead of onclick onclckpendingintent , can't want.
notificationmanager mnotificationmanager = (notificationmanager) this.getsystemservice(context.notification_service); remoteviews remoteviews = new remoteviews(getpackagename(), r.layout.custom_push_layout); notificationcompat.builder mbuilder = new notificationcompat.builder(this) .setsmallicon(r.drawable.ic_launcher) .setcontent(remoteviews) .setautocancel(true); intent intent = new intent(this,gpstrackingactivity.class); final intent yesintent = new intent(intent); final intent nointent = new intent(this, gpstrackingactivity.class); taskstackbuilder yesstackbuilder = taskstackbuilder.create(this); yesstackbuilder.addparentstack(mainactivity.class); yesstackbuilder.addnextintent(yesintent); taskstackbuilder nostackbuilder = taskstackbuilder.create(this); nostackbuilder.addparentstack(mainactivity.class); nostackbuilder.addnextintent(nointent); pendingintent yespendingintent = yesstackbuilder.getpendingintent(0, pendingintent.flag_update_current); pendingintent nopendingintent = nostackbuilder.getpendingintent(0, pendingintent.flag_update_current); remoteviews.setonclickpendingintent(r.id.btn_yes, yespendingintent); remoteviews.setonclickpendingintent(r.id.btn_no, nopendingintent); mnotificationmanager.notify(100, mbuilder.build());
how ?
i know it's kinda late, managed things done via receiver. should:
- create receiver
create 2 intents receiver -
string should_open = "should_open_intent" intent yes = new intent(this, myreceiver.class); yes.putbooleanextra(should_open, true); , same on intent "no"
- wrap them pendingintent
- in receiver, @ function "onreceive" data out using intent.getbooleanextra(shouold_open, default_value_doesnt_matter) , handle accordingly
check out - https://stackoverflow.com/a/26486425/3339597
Comments
Post a Comment