Urban Airship: custom icon for default status bar notification

android, android-notification-bar, android-notifications, urbanairship.com

Solution

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);

Problem

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?

Original source

Related problems