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, b
Here you can read:
Customize default notification
Custom default icon
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.
Custom default Color
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.
Try putting that in your 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.
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>
In this folder: /android/app/src/main/res/values
Also the icon must be in the drawable
folder.
But remember that this icon must be white
with a transparent background.
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.
Read also this SO question that stengthens up what I've said here.
I've tried on the Pixel 2 emulator running API level 27:
Hope it helps.
I know this question is regarding Firebase notification but since on searching the same for local_notifiction grey icon error this post came ...so finally I was able to find the solution to that(in my case icons work fine in debug mode but on building apk icons become grey boxes)
Solution:- in Android/app/src/main/res create a new directory named raw and in that directory add a file named keep.xml and copy paste the following:-
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/*" />
I did the following and it worked for me:
Download the zip folder, unzip and you'll see it contains a res folder with different drawable folders. Copy and paste the contents of the res folder in "android\app\src\main\res" path
Then open the AndroidManifest.xml file and add the following lines to it:
ic_stat_calendar_today is the name of my notification icon. And each of the drawable folders that have been pasted contain a different size of icon with the same name.
If you want to change the color of the icon then check the above image. Add the metadata tag after the notification icon tag
Go to "android\app\src\main\res\values" and add a colors.xml file
<color name="colorAccent">#00FF00</color>
I have shared this answer in the following Github chain as well- Solution.