Firebase通知呈灰色颤动 [英] Firebase Notification is grey flutter

查看:87
本文介绍了Firebase通知呈灰色颤动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase Cloud Messaging将通知发送到我的Flutter应用.它工作正常,但我的应用程序图标通知在Google Pixel XL上为灰色.我可以看到轮廓,但是由于某种原因,它仍然是灰色的.我读过不同的文章,它与Android SDK级别有关,但是Flutter中的minSdkVersion已经是16(小于21),所以我不明白为什么颜色不会显示.

I'm using Firebase Cloud Messaging to send notifications to my Flutter app. It works fine but my app icon notification is grey on the Google Pixel XL. I can see the outline, but for some reason, it's still grey. I've read in different articles that it has to do with the Android SDK level, but the minSdkVersion in Flutter is already 16 (less than 21) so I don't understand why the color won't show on.

是否可以用颜色显示我的应用程序图标以进行通知?

So is it possible to show my app icon for notifications with the color?

-提前感谢

推荐答案

在这里,您可以阅读:

自定义默认通知

自定义默认图标

设置自定义默认图标可让您指定使用的图标 用于通知消息(如果通知中未设置图标) 有效载荷.还可以使用自定义默认图标来设置 从Firebase控制台发送的通知消息. 如果没有自定义 设置了默认图标,并且在通知有效负载中未设置任何图标, 应用程序图标(呈现为白色).

Setting a custom default icon allows you to specify what icon is used for notification messages if no icon is set in the notification payload. Also use the custom default icon to set the icon used by notification messages sent from the Firebase console. If no custom default icon is set and no icon is set in the notification payload, the application icon (rendered in white) is used.

自定义默认颜色

您还可以定义通知使用什么颜色. 不同的android版本以不同的方式使用此设置: Android< N使用它作为图标的背景色. Android> = N 使用它为图标和应用名称着色.

You can also define what color is used with your notification. Different android versions use this settings in different ways: Android < N use this as background color for the icon. Android >= N use this to color the icon and the app name.

尝试将其放入您的AndroidManifest.xml

<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message.  -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/colorAccent" />

您可以在此处找到更多信息.

You can find more info here.

您还需要定义colorAccent.您可以像这样在res文件夹中创建一个colors.xml文件:

You also need to have your colorAccent define. You can create a colors.xml file in your res folder like that:

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

在此文件夹中:/android/app/src/main/res/values

该图标也必须位于drawable文件夹中.

Also the icon must be in the drawable folder.

但是请记住,该图标必须为white,且背景为透明.

But remember that this icon must be white with a transparent background.

对于某些要着色的图标,您需要在某些颜色上设备集meta-tags,您已经在AndroidManifest.xml中添加了该图标,并且您的图标必须符合某些规范(在透明背景中必须为白色).您可以尝试生成一个

For some type of icons to be colored you need on some device sets meta-tags you already added in yuor AndroidManifest.xml and your icon must follow some specifications (must be white in a transparent background). You can try to generate one here. Give it a try. Remember to put it on drawable folder and update the manifest meta-tag icon name.

也请阅读此 SO问题按照我在这里说的话.

Read also this SO question that stengthens up what I've said here.

我尝试了运行API级别27的Pixel 2模拟器:

I've tried on the Pixel 2 emulator running API level 27:

希望有帮助.

这篇关于Firebase通知呈灰色颤动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆