简体   繁体   English

Flutter Firebase 推送通知图标

[英]flutter firebase push notification icon

I made an app and I implemented push notifications and it works but I've tried to change the default icon with a image.png but it's not working the way that I expected.我制作了一个应用程序并实现了推送通知,它可以工作,但我尝试使用image.png更改默认图标,但它没有按我预期的方式工作。 This is how my notification looks:这是我的通知的外观: 在此处输入图片说明

And I want my icon to look like this:我希望我的图标看起来像这样:

在此处输入图片说明

I've added in my android manifest this:我在我的 android 清单中添加了这个:

<!-- 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" />

I don't know what I've done wrong but can you help me?我不知道我做错了什么,但你能帮我吗?

The android:resource (@ folder / name )in the meta-data tag refers to the notification icon should be located in android\\app\\src\\main\\res\\ folder - size \\ name .png. meta-data标签中的android:resource (@ folder / name )是指通知图标应该位于android\\app\\src\\main\\res\\ folder - size \\ name .png。

For your exact scope, you need the drawable - size folder in the specific location with pngs named ic_notifications .对于您的确切范围,您需要特定位置的drawable - size文件夹,其中 png 名为ic_notifications I suggest you use this amazing tool to generate all the required icons with the correct layout (white on transparent).我建议你使用这个神奇的工具来生成所有需要的具有正确布局的图标(透明上的白色)。

Because you also have a color for your notification, you must add the colors.xml in android/app/src/main/res/values which will contain your colorPrimary :因为您的通知也有颜色,所以您必须在android/app/src/main/res/values中添加colors.xml ,其中将包含您的colorPrimary

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

Extra: The android:icon in the application tag refers to the app's icon.额外: application标签中的android:icon指的是应用程序的图标。 Just want to add this extra piece of information because it can be confusing at first when the example found are pretty similar.只想添加这条额外的信息,因为当找到的示例非常相似时,一开始可能会令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM