java - Notification not shown when setGroup() is called in Android KitKat -


i'm testing stackable notifications (stacking notifications article).

i detected in cases notifications not shown after notify() call in devices running android 4.x kitkat.

to problem created code simulates notification (button1) , second notification summary (button2)

private final static int notification_id_a=6; private final static int notification_id_b = 7; private final static int notification_id_summary = 8;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     findviewbyid(r.id.button).setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             shownotif(notification_id_a,false);         }     });     findviewbyid(r.id.button2).setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             shownotif(notification_id_b,false);             shownotif(notification_id_summary,true);         }     }); }  private void shownotif(int notificationid,boolean groupsummary) {     charsequence title="title "+notificationid;     charsequence message="message "+notificationid;     notificationcompat.builder notifbuilder = new notificationcompat.builder(this);     notifbuilder.setsmallicon(r.drawable.icon_notifications);     notifbuilder.setcontenttitle(title);     notifbuilder.setcontenttext(message);     notifbuilder.setgroupsummary(groupsummary);     notifbuilder.setcontentintent(pendingintent.getactivity(this, 0, new intent(this, mainactivity.class), pendingintent.flag_update_current));     notifbuilder.setgroup("group_" + 1);     notificationmanagercompat.from(this).notify(notificationid, notifbuilder.build()); } 

the idea first press button1 , button2. works great in android 5.0+ showing first notif first , summary when second button clicked, in android 4.x button1 not show anything.

where error?

thanks

the short answer appears showing stacked notification on kitkat device not automatically supported support library.

since asked enlightenment here findings based on testing 2 devices running android 4.4.2. using appcompat 23.1.1.

when dig source code of library find when notification shown either use called sidechannel or notificationmanager directly show notification. below notificationmanagercompat.notify method reference showing this:

public void notify(string tag, int id, notification notification) {     // comment: true when notification has      // notificationcompatjellybean.extra_use_side_channel set true.     if (usesidechannelfornotification(notification)) {         pushsidechannelqueue(new notifytask(mcontext.getpackagename(), id, tag, notification));         // cancel notification in notification manager if transitioned being         // side channelled.         impl.cancelnotification(mnotificationmanager, tag, id);     } else {         // comment: calls notificationmanager.notify(id, notification); in base implementation         impl.postnotification(mnotificationmanager, tag, id, notification);     } } 

now when show notification without setting group notification shown using notification manager works, if group set attempt use side channel send notification , cancel notification shown using notification manager seen in above method.

proof side channel used when group set found in notificationcompatkitkat.builder see following code:

if (groupkey != null) {     mextras.putstring(notificationcompatjellybean.extra_group_key, groupkey);     if (groupsummary) {         mextras.putboolean(notificationcompatjellybean.extra_group_summary, true);     } else {         mextras.putboolean(notificationcompatjellybean.extra_use_side_channel, true);     } } 

this not seem big deal until @ pushsidechannelqueue(...) method when showing notification using sidechannel.

it ends looking service can handle action android.support.bind_notification_side_channel of there not 1 default method returns. causing notification never shown.

there notificationcompatsidechannelservice abstract class in compatibility library can implement according documentation if want write own sidechannelservice seems better off not using grouped notifications in kitkat , prior devices.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -