12

When I add notification:

        NotificationCompat.Builder mBuilder =
                            new NotificationCompat.Builder(this)  
              .setSmallIcon(R.drawable.plus)
.setContentTitle(title)
.setAutoCancel(true) 
.setContentText(text)
.setSound(RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setLargeIcon(bm);

I see large icon and small in it: enter image description here

How can I set only large Icon, without small. If use only setLargeIcon, I don't see notification at all, just sound alert.

Walter West
  • 829
  • 3
  • 12
  • 31

5 Answers5

17

Small icon is mandatory. If you don't set a large one you'll get your small icon bigger in the middle of the circle with the color of your choice (setColor).

If i were you i'd put that blank E on a transparent background for smallicon, and set a red color for the circle.

Xavier Falempin
  • 1,186
  • 7
  • 19
9

get the small icon id and then try to hide it

int smallIconId = ctx.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconId != 0) { 
    if (notification.contentView!=null)
        notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
}

try looking at this post it will help too

i test the code on api 18,23 (samsung j1,galaxy S6) work fine

ChinLoong
  • 1,735
  • 24
  • 26
ShahinFasihi
  • 624
  • 7
  • 13
  • 2
    notice : small icon is required one that means you should set value for that , but you can try the code above to hide small icon ,... – ShahinFasihi Apr 28 '16 at 19:46
  • Or just set a transparent one and don't make crazy asumptions about the icon id not changing name – Xavier Falempin May 12 '16 at 12:41
  • i did not try to transparent the small icon but working with id was good for me ;) but finally it is your way if you say so – ShahinFasihi May 13 '16 at 21:25
  • Setting a transparent icon doesn't work as you don't see you icon in the status bar then. Instead you should create a custom content view and pass it to the builder with setContentView – Marcel Derks Sep 22 '16 at 11:02
  • Above code helped to hide the small icon when user pull the notification. But in lint shows "notification.contentView" is deprecated, any alternative for this to remove warning? – ashok reddy Dec 03 '16 at 13:59
  • @ashokreddy I use `@SuppressWarnings("deprecation")` and I don't worry about it unless I need ro raise the API levels. – soger Apr 21 '17 at 11:01
2

Based on the previous answer you can also hide the expended view too :

int smallIconId = AnghamiApp.getContext().getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
            if (smallIconId != 0) {
                notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
                notification.bigContentView.setViewVisibility(smallIconId, View.INVISIBLE);
            }
awsleiman
  • 1,879
  • 20
  • 14
0

You can create a custom notification and then show whatever you want in the large notification area. See and example here TutorialsFace: Build all types of Notifications in Android

EZDsIt
  • 921
  • 1
  • 9
  • 14
-1
public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Notification notification = new NotificationCompat.Builder(this)
            .setContentTitle("Test")
            .setContentText("Hii There")
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.smallicon))
            .setAutoCancel(true)
            .build();
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(123, notification);
  }
}
slfan
  • 8,950
  • 115
  • 65
  • 78
  • Hii Everyone this is my first answer sorry i give late answer..Please Try this answer you get title Msg and large icon ignore class things you can implement it any class – Deepak Vishwakarma Apr 08 '19 at 10:59