【发布时间】:2021-04-06 15:22:17
【问题描述】:
我在推送通知中添加了小图标,但仍未显示。我正在使用安卓 10 模拟器。我的图标满足使用无背景的白色并存储在 mipmap 文件夹中的要求。我在stackoverflow上尝试了一些解决方案,但仍然无法正常工作。 这是我的代码
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_notification)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true);
我已经尝试在 android manifest 上添加此代码,但仍然无法正常工作
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_notification" />
我的 targetSDK 是 29
你有没有遇到过同样的问题并解决了?
【问题讨论】:
-
您是否尝试过使用
drawable文件夹中的其他图片? -
@SamChen 我试过了,但也没有用
-
@FairuzYassar 我还建议您尝试从
drawable文件夹加载图像。我总是做的是,首先获取一个 .svg 图标,将其作为矢量资源导入到drawable文件夹中,这一步的结果将是生成的 .xml 布局文件。最后像这样在NotificationCompat.Builder中调用这个布局文件.setSmallIcon(R.drawable.ic_yourIcon)就可以了。 -
@BWappsandmore 我已经尝试过您的解决方案,但通知图标仍然显示如上图的灰色方块
-
@Fairuz Yassar 在互联网上搜索免费的
.svg图标。下载它。在 Android Studio 中,右键单击您的drawable文件夹,然后选择New -> Vector Asset。选择本地文件(SVG、PSD)作为资产类型。选择您下载的图标。从它生成.xml布局文件后,单击它进行编辑。编辑android:height="24dp"和android:width="24dp"或调整大小、36dp 或 48dp。您将从编辑器左侧的图标中看到预览。将此文件附加到您的通知中。
标签: android react-native push-notification firebase-cloud-messaging clevertap