Firebase通知始终显示空白图标

时间:2016-10-03 09:44:14

标签: android firebase android-notifications firebase-cloud-messaging firebase-notifications

我是 FCM 的新人。我无法使 FCM 使用我的应用图标作为通知图标,图标始终为白色空白。

我将图标导入mipmap个文件夹,但似乎没有任何变化。正如一些家伙所说,这是因为棒棒糖通知为in this question

但问题是, FCM 通知会自动弹出,我无法让“通知”构建器覆盖该图标。我怎样才能改变它?

6 个答案:

答案 0 :(得分:28)

这是FCM的默认行为。当应用程序在后台时,它将采用白色图标。

使用此标记并将其放入您的清单中。对我来说这很有效。希望它也适合你

<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_app_icon" />

答案 1 :(得分:10)

如果您遇到此问题

enter image description here

请参阅此链接:Icon not displaying in notification: white square shown instead

我遇到了同样的问题。我通过设计师制作透明图像来解决。 确保您的徽标应为72 * 72像素。

注意:不要浪费时间去搜索这个问题,你只需要一个72 * 72尺寸的透明图标。

答案 2 :(得分:1)

我遇到了同样的问题,在这里做了所有建议,没有任何效果。

最终,将Firebase插件从11.8.0降级到11.6.0即可解决问题。

这也可能对某人有所帮助。

答案 3 :(得分:0)

当未为传入通知设置任何图标时,firebase将采用默认图标并显示通知。

要覆盖默认图标,请在您的Android清单文件中添加以下代码

<meta-data
 android:name="com.google.firebase.messaging.default_notification_icon"
 android:resource="@drawable/ic_stat_ic_notification" />

有关更多信息,您可以按照link

答案 4 :(得分:0)

将您的通知保持为 72 x 72 ,并使其完全白色。看到附带此答案的照片。

然后将以下代码粘贴到清单中。

<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
 android:resource="@drawable/ic_stat_money" />

enter image description here

您可以从Android Studio的默认图标包中制作一个新图标。

为此,请右键单击您的可绘制文件夹> 新建> 图像资产

答案 5 :(得分:0)

唯一对我有用的是在 Android Studio 中生成通知图标图像资产。 要将图像用作通知图标,只需将资产类型设置为“图像”并选择文件。

提示#1:在透明背景上使用白色图标!

提示#2:如果窗口右侧的预览仅包含白色方块,则您的通知图标看起来就像那样 - 白色方块! enter image description here

提示 #3:资产的名称应该添加到 AndroidManifest 的 meta-data 标签中

<meta-data
 android:name="com.google.firebase.messaging.default_notification_icon"
 android:resource="@drawable/whatever_you_set_for_image_asset_name" />

来源:取自this answer

相关问题