Notification doesn't show up if only large ico

2019-08-02 07:30发布

问题:

I want to add a large icon to my notification, but when I run the app, the notification doesn't show up.

When I change to small icon, it works but icon is too small.

Below is my code, any help where it is wrong?

Bitmap rawBitmap = BitmapFactory.decodeResource(getResources(),
                                                     R.drawable.ic_launcher);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
    .setLargeIcon(rawBitmap)
    .setContentTitle("Alert")
    .setContentText("CITRUS PUNCH Minute Maid expired");
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, mBuilder.build());

回答1:

Per the notification guide list of required fields, you must set a small icon via the setSmallIcon() method. Generally, this icon looks like your application icon, although entirely as white over a transparent background per the notification iconography guide: tools such as the Notification Icon Generator may help in building an appropriate small icon.

On Android 5.0+ devices, you can use setColor() to set a branded background color for behind your small icon.

Large icons are not meant for branding purposes - instead, they should be used to make it personal and be an image associated with the sender of the notification (i.e., a profile picture) or additional information to convey the meaning of the notification.