如何更改从Firebase Cloud Messaging Flutter发送的通知图标。

huangapple go评论70阅读模式
英文:

How to change notification icon sent from Firebase Cloud Messaging Flutter

问题

我正在学习使用Flutter和Firebase Cloud Messaging来实现推送通知。

我已成功在Android上显示了我从Firebase控制台发送的通知,但问题是显示的图标与我的应用图标不匹配,就像这样:
如何更改从Firebase Cloud Messaging Flutter发送的通知图标。

如何更改图标?
谢谢

更新
实际上,我认为这是我提供的资源形式的问题。因为如果通知位置出现而您不打开通知栏,那么图标的颜色就是应该的。

但是当您打开通知栏时,图标变为灰色,原因不明...

因为我看到了一些应用程序也是这样,其中甚至有一个银行应用程序。

英文:

So I'm learning about push notifications using Firebase Cloud Messaging using Flutter.

I've successfully displayed the notification in Android I sent from the Firebase console, but the problem is that the icon that appears doesn't match my app icon, like this:
如何更改从Firebase Cloud Messaging Flutter发送的通知图标。

How do I change the icon?
Thank You

UPDATE
So actually I think this is a problem with the form of assets that I provide. Because if the notification position comes in and you don't open the notification tray, then the icon is the color it should be.

But when you open the notification tray, the icon becomes gray, for some reason...

Because I saw several applications like that, one of which was even a bank application

答案1

得分: 1

你需要修改Android配置并提供自定义通知图标。

更改通知图标的步骤:

将自定义通知图标放置在您的Flutter项目中的适当位置(最好是白色轮廓图标,带有透明背景):android/app/src/main/res/drawable

确保您的图标名称与下一个配置文件中的名称匹配,在这里它将是notification_icon.png

打开android/app/src/main/AndroidManifest.xml

<application>标签内添加以下代码行:

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

android:resource属性应指向您放置在drawable文件夹中的自定义通知图标。

重新构建后,应该已更新。

英文:

You need to modify the Android configuration and provide a custom notification icon.

Steps to change the notification icon:

Place the custom notification icon in the appropriate location in your Flutter project (prefer a white silhouette icon on a transparent background) : android/app/src/main/res/drawable

Ensure that the name of your icon matches the name in the next config file, here it will be notification_icon.png .

Open the android/app/src/main/AndroidManifest.xml

Add the following lines of code inside the &lt;application&gt; tag:

&lt;meta-data
android:name=&quot;com.google.firebase.messaging.default_notification_icon&quot;
    android:resource=&quot;@drawable/notification_icon&quot; /&gt;

The android:resource attribute should point to the custom notification icon you placed in the drawable folder.

After rebuild it should be updated

huangapple
  • 本文由 发表于 2023年6月12日 16:23:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454776.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定