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.
Related
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>
I made an app and I implemented push notifications and it works but I've tried to change the default icon with a image.png but it's not working the way that I expected. This is how my notification looks:
And I want my icon to look like this:
I've added in my android manifest this:
<!-- Add custom icon to the notifications -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_notifications" />
<!-- Change the color of the icon -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorPrimary" />
I don't know what I've done wrong but can you help me?
The android:resource (#folder/name)in the meta-data tag refers to the notification icon should be located in android\app\src\main\res\ folder-size\ name.png.
For your exact scope, you need the drawable-size folder in the specific location with pngs named ic_notifications. I suggest you use this amazing tool to generate all the required icons with the correct layout (white on transparent).
Because you also have a color for your notification, you must add the colors.xml in android/app/src/main/res/values which will contain your colorPrimary:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FFFFFF</color>
</resources>
Extra: The android:icon in the application tag refers to the app's icon. Just want to add this extra piece of information because it can be confusing at first when the example found are pretty similar.
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
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.
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