Flutter Firebase 推送通知图标

3

我开发了一个应用程序,并实现了推送通知功能,它可以正常工作,但我尝试使用image.png更改默认图标,但效果并非我所期望的。这是我的通知显示方式:enter image description here

我希望我的图标看起来像这样:

enter image description here

我在安卓清单文件中添加了以下内容:

<!-- Add custom icon to the notifications -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notifications" />
<!-- Change the color of the icon -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorPrimary" />

我不知道我做错了什么,但你能帮我吗?

1个回答

7

meta-data标签中的android:resource (@folder/name)指的是通知图标应该位于android\app\src\main\res\folder-size\name.png。

对于您的具体范围,您需要在特定位置使用drawable-size文件夹,并命名为ic_notifications的png文件。我建议您使用这个令人惊叹的工具来生成所有所需的图标及正确的布局(白色透明背景)。

因为您还有一个通知的颜色,所以您必须在android/app/src/main/res/values中添加colors.xml文件,其中包含您的colorPrimary

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#FFFFFF</color>
</resources>

额外信息:application标签中,android:icon指的是应用程序的图标。我想补充这个额外的信息,因为当找到的示例非常相似时,一开始可能会感到困惑。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接