I'm facing an issue with push notifications in .NET MAUI. I'm using Firebase Cloud Messaging and I have successfully integrated it into my app. The problem is with the notification icon; when I receive a notification while using the app, the icon is displayed correctly, but if I receive the notification when the app is closed, the icon appears small and inside a larger circle (which doesn't look good). I've tried using both SVG and PNG files with colored or white and transparent backgrounds, but nothing seems to work. That's the image I have used.
Here are the screenshots of the problem:
And if I scroll down while in the app:
Outside the app (when closed):
And again, if I scroll down while the app is closed:
These examples were made using a PNG file named small_notification_icon.png and saved in the Resources/Images folder, which only uses white color with a transparent background. This is the code I used:
var notificationBuilder = new NotificationCompat.Builder(this, MainActivity.ChannelID)
.SetSmallIcon(Resource.Drawable.small_notification_icon)
.SetContentTitle(title)
.SetContentText(messageBody)
.SetChannelId(MainActivity.ChannelID)
.SetPriority((int)NotificationPriority.High);
var notificationManager = NotificationManagerCompat.From(this);
notificationManager.Notify(MainActivity.NotificationID, notificationBuilder.Build());
I would appreciate any help or suggestions on how to resolve this issue.
I've identified the issue. When the app runs in the background, notifications sent from the console use the launcher icon designated in the manifest file.
To address the problem, you can simply replace the default image specified in the AndroidManifest
by inserting the following code within the Application
tag. All you need to do is substitute your_favourite_image with the image you prefer for the notification icon.
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/your_favourite_image" />
This should resolve the issue and allow you to use your preferred image for notifications.