Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotificationCompat android - how to show only Large icon without small

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.

like image 222
Walter West Avatar asked Jun 17 '15 09:06

Walter West


3 Answers

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.

like image 182
Xavier Falempin Avatar answered Nov 06 '22 06:11

Xavier Falempin


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

like image 9
ShahinFasihi Avatar answered Nov 06 '22 07:11

ShahinFasihi


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);
            }
like image 2
awsleiman Avatar answered Nov 06 '22 06:11

awsleiman