Monday, 15 July 2013

java - Action button from notification bar not working Android -



java - Action button from notification bar not working Android -

i'm creating force notification on service:

appointmentservice.java

intent intent = new intent(appointmentservice.this, reappointmentservice.class); intent.putextra("id", id); pendingintent pintent = pendingintent.getservice(appointmentservice.this, 0, intent, 0); notification n = new notificationcompat.builder(appointmentservice.this) .setcontenttitle((string) snapshot.child("name").getvalue()) .setcontenttext("hey!") .setsmallicon(r.drawable.ic_launcher) .setautocancel(true) .addaction(r.drawable.ic_action_reply_light, "hey yo!", pintent) .build(); notificationmanager notificationmanager = (notificationmanager) heyservice.this.getsystemservice(activity.notification_service); notificationmanager.notify(getnotificationid(id), n);

reappointmentservice.java @override public ibinder onbind(intent arg0) { homecoming null; }

@override public int onstartcommand(intent intent, int flags, int startid) { bundle extras = intent.getextras(); string id = extras.getstring("id"); gc = new globalcontents(this); firebase send = new firebase("https://appointmentapp.firebaseio.com/app/"+id); firebase ref = send.push(); ref.runtransaction(new transaction.handler() { @override public transaction.result dotransaction(mutabledata ref) { ref.child("date").setvalue(string.valueof((new gregoriancalendar()).gettimeinmillis())); ref.child("name").setvalue(gc.getname()); ref.child("from").setvalue(gc.getid()); ref.child("seen").setvalue(false); homecoming transaction.success(ref); } @override public void oncomplete(firebaseerror error, boolean committed, datasnapshot currentdata) { } }); homecoming start_not_sticky; }

the notification shows action button. but, when click on button, nil happens (i've tried set logs on reappointmentservice , didn't work).

what problem?

the lastly parameter pendingintent.getservice should flag_update_current - otherwise pendingintent not updated new extras per documentation on pendingintent:

a pendingintent reference token maintained scheme describing original info used retrieve it. means that, if owning application's process killed, pendingintent remain usable other processes have been given it. if creating application later re-retrieves same kind of pendingintent (same operation, same intent action, data, categories, , components, , same flags), receive pendingintent representing same token if still valid, , can phone call cancel() remove it.

because of behavior, of import know when 2 intents considered same purposes of retrieving pendingintent. mutual error people create create multiple pendingintent objects intents vary in "extra" contents, expecting different pendingintent each time. not happen. parts of intent used matching same ones defined intent.filterequals. if utilize 2 intent objects equivalent per intent.filterequals, same pendingintent both of them.

java android

No comments:

Post a Comment