问题描述
我想在通知中添加一个大图标,但是当我运行该应用程序时,该通知不会显示.
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());
推荐答案
每个必填字段通知指南列表,您必须通过 setSmallIcon()方法.通常,此图标看起来像您的应用程序图标,尽管根据通知图标指南:诸如通知图标生成器之类的工具可能会帮助构建适当的小图标.
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.
在Android 5.0+设备上,您可以使用 setColor()为您的小图标后面设置品牌背景颜色.
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.
这篇关于如果仅设置了大图标,则不会显示通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!