我制作了一个应用程序并实现了推送通知,它可以工作,但我尝试使用 image.png
更改默认图标,但它没有按我预期的方式工作。这是我的通知的外观:
我希望我的图标看起来像这样:
我在我的 android manifest 中添加了这个:
<!-- 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" />
我不知道我做错了什么,但你能帮帮我吗?
最佳答案
meta-data
标签中的 android:resource
(@folder
/name
) 指的是通知图标应位于 android\app\src\main\res\folder
-size
\name
.png.
对于您的确切范围,您需要位于特定位置的 drawable
-size
文件夹,其中包含名为 ic_notifications
的 pngs。我建议你用这个amazing tool生成具有正确布局的所有必需图标(透明上的白色)。
因为您的通知也有颜色,所以您必须在 android/app/src/main/res/values
中添加 colors.xml
,其中将包含您的colorPrimary
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FFFFFF</color>
</resources>
Extra: application
标签中的android:icon
指的是应用程序的图标。只是想添加这条额外的信息,因为当找到的示例非常相似时,一开始可能会令人困惑。
关于android - flutter 的firebase推送通知图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64304512/