Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Urban Airship: custom icon for default status bar notification

Urban Airship recommends creating a custom notification with CustomPushNotificationBuilder if you want to make any modifications to the status bar notification, including trivially changing the icon.

Unfortunately, using a RemoteView for notifications carries many unwanted implications with it related to custom manufacturer and/or platform-specific skins, including text colors and references to private resources (for instance @*android:drawable/notify_panel_notification_icon_bg_tile on Honeycomb/ICS).

There must be a simple way to swap the icon without using RemoteView. How?

like image 672
Paul Lammertsma Avatar asked Dec 20 '22 21:12

Paul Lammertsma


1 Answers

I found that by overriding BasicPushNotificationBuilder, I can set the icon quite trivially:

BasicPushNotificationBuilder nb = new BasicPushNotificationBuilder() {
    @Override
    public Notification buildNotification(String alert,
            Map<String, String> extras) {
        Notification notification = super.buildNotification(alert,
                extras);
        // The icon displayed in the status bar
        notification.icon = R.drawable.notification;
        // The icon displayed within the notification content
        notification.contentView.setImageViewResource(
                android.R.id.icon, R.drawable.notification);
        return notification;
    }
};
// Set the custom notification builder
PushManager.shared().setNotificationBuilder(nb);
like image 97
Paul Lammertsma Avatar answered Mar 08 '23 16:03

Paul Lammertsma