20

I'm new with FCM. I cannot make FCM use my app icon as notification icon and the icon is always a white blank one.

I imported an icon to mipmap folders but nothing seems changed. As some dude say that this is because of lollipop notification as in this question

But the problem is, the FCM notification automatically pops up and I cannot get the Notification builder to override the icon. How can I change it?

Alireza Noorali
  • 3,469
  • 2
  • 23
  • 60
Mahdi
  • 5,031
  • 5
  • 46
  • 96
  • please post your code. – D.J Oct 03 '16 at 09:44
  • @Bansal what for? on Lollipop and above notification's icons are white ... asked bazillion times – Selvin Oct 03 '16 at 09:48
  • Possible duplicate of [Notification bar icon turns white in Android 5 Lollipop](http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop) – Selvin Oct 03 '16 at 09:49
  • @Selvin it is not the same question, cause I do not pop notification by my self in firebase so I do not control on icon and color. – Mahdi Oct 25 '16 at 06:01
  • @Mateusz Pryczkowski your answer is right post it again – Mahdi Oct 25 '16 at 09:15
  • You always have access to notification. your app can not show notification without setting FirebaseMessagingService.check https://firebase.google.com/docs/cloud-messaging/android/receive There you can use solution from given link in your question itself – Harry's Lab Mar 30 '17 at 08:43

6 Answers6

38

This is the default behaviour of FCM. When app is in background it will take white icon.

Use this tag and put it in your Manifest. For me this worked. Hope it works for you too. Ensure meta-data is inside application like the example mentioned in quickstart

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    tools:ignore="GoogleAppIndexingWarning">
    <!-- [START fcm_default_icon] -->
    <!-- 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" />
    <!-- [END fcm_default_icon] -->
    <!-- [START fcm_default_channel] -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id" />
    <!-- [END fcm_default_channel] -->
    <activity
        android:name=".EntryChoiceActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".kotlin.MainActivity" />
    <activity android:name=".java.MainActivity" />
Anand Rockzz
  • 4,552
  • 3
  • 46
  • 58
15

If you are having this problem

enter image description here

See this link: Icon not displaying in notification: white square shown instead

I had the same problem. I solved by making transparent image from designer. Make sure your logo should be 72*72 pixels.

NOTE: Don't time waste in googling this issue, you just need a transparent icon which should be 72*72 dimensions.

Community
  • 1
  • 1
Däñish Shärmà
  • 2,743
  • 2
  • 22
  • 41
  • 1
    "An answer" which is only link to a duplicate question is not an answer... – Selvin Oct 03 '16 at 09:51
  • 2
    I gave him exact answer so he might not waste his time and focus on solving the issue. – Däñish Shärmà Oct 03 '16 at 09:53
  • thanks i saw the link. but where should I implement Notification builder. cause in FCB android pop notification automatically. – Mahdi Oct 03 '16 at 10:56
  • I up voted you because it was part of my answer. but I can not replace FCM auto generated notification icon. – Mahdi Oct 03 '16 at 20:26
  • actually fcm is totally different from gcm. There are two types of notifications in fcm. You have to study about it. This is the very good documentation https://github.com/codepath/android_guides/wiki/Google-Cloud-Messaging . One more thing in fcm if your app is in background, notifications won't hit onMessageReceived(). For this you need to do server side coding. from server the response should be like, check this link http://stackoverflow.com/questions/37358462/firebase-onmessagereceived-not-called-when-app-in-background , see(Ankit Adlakha) answer – Däñish Shärmà Oct 04 '16 at 04:02
  • also add in manifest file above application tag :) – Android User Jan 19 '19 at 05:47
  • 2
    @DäñishShärmà, you are right. Your *NOTE* helped me alot :) – Raghu Mudem Mar 12 '19 at 19:51
  • Also, icon should not be SVG – konstantin_doncov Nov 16 '19 at 15:56
  • That's worked, thank you. One small note, don't use [android:name="com.google.firebase.messaging.default_notification_color"] in this case. – Maxim Firsoff Jan 27 '21 at 10:12
1

I faced same problem and did everything suggested here and nothing worked.

Eventually, downgrading the firebase plugin from 11.8.0 to 11.6.0 resolves it with the help of this github issue.

This might also help someone.

Aweda
  • 249
  • 3
  • 10
1

Keep your notification small as 72 x 72 and make it completely white. See the photo attached with this answer.

Then paste the codes below into your manifest.

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

enter image description here

You can make a new icon from default icons pack of Android Studio.

For this right click on your drawable folder > New > Image Asset

XpressGeek
  • 828
  • 1
  • 10
  • 21
0

When no icons are set for incoming notifications, firebase will take the default icon and shows notification.

To override the default icon add below code into your Android manifest file

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

For more information you can follow the link

Kemparaju
  • 28
  • 1
  • 5
0

The only thing that worked for me was to generate a Notification icon image asset in Android studio. To use the an image as the notification icon, just set Asset type to "Image" and select the file.

Tip #1: use an icon which is of white color, on transparent background!

Tip #2: if the preview on the right side of the window contains only white squares, your notification icon will look just like that - white squares! enter image description here

Tip #3: the Name of the asset is what should be added into the meta-data tag in AndroidManifest

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

Source: Taken from this answer

Aleksandar
  • 1,367
  • 16
  • 28