15

I have a notification that displays a largeicon.

Is there any way to remove the smaller icon from honeycomb and above devices from this view?

Obviously still keeping the small icon for the top status bar

enter image description here

   NotificationCompat.Builder builder = new NotificationCompat.Builder(context)


            // Set required fields, including the small icon, the
            // notification title, and text.
            .setSmallIcon(R.drawable.ic_notify_status_new)
            .setContentTitle(title)
            .setContentText(text)


            // All fields below this line are optional.

            // Use a default priority (recognized on devices running Android
            // 4.1 or later)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)

            // Provide a large icon, shown with the notification in the
            // notification drawer on devices running Android 3.0 or later.
            .setLargeIcon(picture)

            .setContentIntent(
                    PendingIntent.getActivity(
                            context,
                            0,
                            notiIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT)
            );


    builder = getNotiSettings(builder);
    notify(context, builder.build());
zeroprobe
  • 580
  • 1
  • 8
  • 19

3 Answers3

14

Add this code after you build the notification.

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int smallIconViewId = getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());

        if (smallIconViewId != 0) {
            if (notif.contentIntent != null)
                notif.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notif.headsUpContentView != null)
                notif.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notif.bigContentView != null)
                notif.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
        }
    }

where "notif" is your built notification,

Ziv Kesten
  • 1,206
  • 25
  • 41
  • thanks a lot , it works for me and i do not check the SDK_INT ,just getting smallIconViewId and set view as invisible works good on api lower than 21 too – ShahinFasihi Apr 28 '16 at 19:38
  • Did you mean if (notif.contentView != null) instead of notif.contentIntent? – Minas Mina May 10 '16 at 17:03
  • No i did not, this is the intent to execute when the expanded status entry is clicked – Ziv Kesten May 11 '16 at 04:28
  • What's the relationship between notif.contentIntent and notif.contentView? – Ranmocy Aug 05 '16 at 02:12
  • 1
    Please change `if (notif.contentIntent != null)` to `if (notif.contentView != null)` – almisoft Aug 17 '17 at 09:29
  • 3
    `Notification.contentView.setImageViewResource()` works, but `contentView` is deprecated. But using `NotificationCompat.Builder.getContentView().setImageViewResource()` (before or after `NotificationCompat.Builder.build()` or `NotificationManager.notify()`) does not work – almisoft Aug 17 '17 at 09:36
1

There is only one way: Use your custom layout

Your question is probable a duplicate of NotificationCompat 4.1 SetSmallIcon and SetLargeIcon

Community
  • 1
  • 1
Jean Y.C. Yang
  • 4,382
  • 4
  • 18
  • 27
-1

Use only setSmallIcon for Your icon. It will be also used for largeIcon if second wasn't specified (just make sure it is big enough to fit both).

Make sure that it looks good on pre-lolipop, lolipop and above. For example here I do set application icon only for pre-lolipop devices, where lolipop and above are getting different smallIcon and same largeIcon as smallIcon.

int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
    notificationBuilder
        .setSmallIcon(smallIcon)
        .setLargeIcon(appIconDrawable)
} else {
    notificationBuilder.setSmallIcon(appIconDrawable);
}
Darek Deoniziak
  • 763
  • 8
  • 17