Firebase Notification Always shows blank icon - android

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?

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

If you are having this problem
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.

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

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" />
You can make a new icon from default icons pack of Android Studio.
For this right click on your drawable folder > New > Image Asset

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.

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

Related

Android icon gets picked up instead of notification icon

I am using FCM notification and I have set the following in my AndroidManifest.xml:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/splash" />
<!-- 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/splash_color" />
where splash is a transparent png image.
I also have the android app icon which I am setting like this in the same manifest file:
<application
android:name="io.flutter.app.FlutterApplication"
android:label="myapp"
android:icon="#drawable/ic_launcher">
What happens is that when a notification pops up, it picks up the ic_launcher instead of splash. If I replace ic_launcher and keep splash as my android icon, then I see the notification icon.
However, if I do it this way, then my app icon (which is now a transparent image) get's a black color as background which I don't want. I want the ic_launcher to be my background color. I fail to understand as to why the image defined at android:icon gets picked up for notification ?
For anyone struggling with this, please put the meta-tags right after the application tag. Do not put them under the activity tag. So something like this:
<application
android:name="io.flutter.app.FlutterApplication"
android:label="When Coin"
android:icon="#mipmap/ic_launcher">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_notification" />
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

Issue displaying flutter app icon on certain versions of android

I have a flutter app in which I have generated app icons for under the android folder of the project with the image asset tool that comes with android studio. On certain versions of android however neither this icon or flutter's default icon displays which seems to tell me this isn't just an issue with the icons I've provided, I instead get the default green android as such:
The screenshots above have come from an android 5 emulator (albeit quite old now its still technically supported by flutter so I wanted to test this) and I get the same problems on a physical device running android 7, but the icon seems to appear fine on any versions above. Something else I have noticed is that no app name appears in the multitasking menu but I'm not sure if that is a completely unrelated issue.
If anyone could help me that would be great, as I can't figure out what other icons I need to place in the project as I thought I'd covered all options. Thanks.
Edit- This is the android manifest for my app:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.letalis.testapp">
<application
android:label="Test App"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Res folder:
Follow these Steps to Change/Customize Launcher Logo in Android Studio,
*Expand the project root folder in the Project View
*Right Click on the app folder
*In the Context Menu go to New->Image Asset
*In the pop up that appears select the the new logo you would like to have(image/clip art/text).
*If you were selecting the image radio button (as is the default choice), if you clicked on the 3-buttons to show the path tree to locate your .png image file, most probably you might not be seeing it, so drag it from the Windows Explorer (if Windows) and drop it in the tree, and it will appear and ready for being selected.
**Don't forget to set new icon's location in manifest: replace drawable to minimap in android:icon –
..........Mipmap Solution:
As you can see this Snapshot, I set Mipmap for every version, you can follow this also,
You have to create an XML file for anydpi-v26
`<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#color/ic_launcher_background"/>
<foreground android:drawable="#mipmap/ic_launcher_foreground"/>
</adaptive-icon>`

Colorful FCM Notification icon

I was just wondering how could you set a multi colored notification icon using FCM since right now i'm using the snippet below in AndroidManifest.xml to color it and its only possible to have one color.
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_default" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
You can able to define the color at the time of showing the notification refer the below link
Android Color Notification Icon

Grey square notification Torturous

I created an app which generates a notification, but the icon I set for that notification is not being displayed. Instead I get a white square.
From stackoverflow and other websites i try to look for solution but no luck.
Note: I am php developer and know limited andoroid development.
My code:
AndroidManifest
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_name" />
<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/app_name"/>
Images are generated using image asset tools as shown below.
NOTE : It works well on my old samsung s7 edge but doesnot not work on my motog4 motog5 oneplusone and oneplusthree
You notification icon has incorrect transparent areas. You must ensure, that your transparency is 100%, other alpha channel values will be mapped to white.

FCM - When setting icon in meta data, should I use the mipmap folder?

To set a default icon with FCM we can add a meta tag in the Android manifest. Mine currently looks like below because I'd like to use my application's icon as the notification icon when receiving push notifications:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_logo_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
Notice I am getting ic_logo_launcher.png from the mipmap folder. Is this advisable?
Yes ! You can ...though firebase takes app_icon by default
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/notificationBackground" />
But its better to use icon from #drawable which will have alpha and white icon.

Categories

Resources