Custom expandable notifications in Jelly Bean (4.1)
Asked Answered
S

2

18

Jelly Bean added support for expandable status notification. According to http://developer.android.com/about/versions/jelly-bean.html:

In addition to the templated styles, you can create your own notification styles using any remote View.

How do do this? I believe to do this you need to create a custom Notification.Style. It's an abstract class so I it needs to be extended. I haven't been able to find any documentation on which parts need to be extended.

This SO question gives a good example of how to use the notificaiton.builder for basic notificaitons, I'm using this as a starting point. Adding

.setContent(new RemoteViews(getPackageName(), R.layout.notification)) 

adds a custom view for basic notifications, but it's not expandable.

Swank answered 12/9, 2012 at 4:42 Comment(0)
E
26

You need to create your own RemoteViews, then indicate that you want the expanded content to inherit your custom RemoteViews.

 RemoteViews expandedView = new RemoteViews(YOUR CONTEXT.getPackageName(), YOUR CUSTOM LAYOUT);
 Notification notification = mBuilder.build();
 notification.bigContentView = expandedView;

Note that bigContentView is what you're looking for. mBuilder is a Notification.Builder object.

Ernaernald answered 12/9, 2012 at 5:1 Comment(0)
R
13

There's a good tutorial here on how to do it and how to create your own layout too.

enter image description here

Basically you need to create a remoteView with your layout and then set it as bigContentView in the Notification object. Btw make sure you also add the reguler contentView because the OS will use the smaller contentView in some cases.

Rosalindarosalinde answered 14/9, 2012 at 20:14 Comment(3)
link updated once again feras.us/blog/custom-rich-notification-view-androidAnticlinorium
the link is down againNiche
@LangustenGustel Updated again with the direct link to github pages.Rosalindarosalinde

© 2022 - 2024 — McMap. All rights reserved.