Custom Notification in Android
With Android 3.0 “Honeycomb” new notification have have become customizable. This allows to display rich content within the notification panel. While this is of course one of the features to be used with care — not to overload the GUI — it can be quite useful.
There are two two options open:
android.widget.RemoteViewsto display the notification data. This is done by calling
android.app.Notification.Builder.setContent. (available since Android 3.0).
Use a notification style (
android.app.Notification.Style) to create a view which can switch between a standard views and expanded view (available since Android 4.2).
After evaluating them both — including some try error and abandon what does not work at all my suggestions are:
If your data fits in any of the new styles use them. Preferably using
android.support.v4.app.NotificationCompat.Builderso backward compatibility is ensured.
If it does not fit into one of the new styles then don’t try create a custom style by sub-classing
android.app.Notification.Style. To much of the class, its factory companion
android.app.Notification.Builderas well as the associated resources are declared private. So you eventually end up reimplementing the whole notification styles framework.
If you wish to create a true custom notification then create an
In rest of the Article I show how you create a custom notification which can display two lines of text — instead of just one line like it is possible with the normal notification.