question

GordonS-9701 avatar image
0 Votes"
GordonS-9701 asked LeonLu-MSFT commented

Notification Icon not correct

I am creating a notification which is displaying OK on iOS but it isn't fully correct on Android.

The following code creates the notification, when the app is in the foreground:

             int NOTIFICATION_ID = 1000;
             var channelId = FirebasePushNotificationManager.DefaultNotificationChannelId;
             var msgTitle = e.Data["title"].ToString(); // "title";
             var msgContent = e.Data["body"].ToString(); // "message content";
    
             // Build the notification:
             var builder = new NotificationCompat.Builder(this, channelId)
                           .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it
                           .SetContentTitle(msgTitle) // Set the title
                           .SetSmallIcon(Resource.Drawable.k_notification_icon) // This is the icon to display
                           .SetContentText(msgContent); // the message to display.
    
             builder.SetLargeIcon(Android.Graphics.BitmapFactory.DecodeResource(Resources, Resource.Drawable.k_notification_icon));
    
             // Publish the notification:
             var notificationManager = NotificationManagerCompat.From(this);
             notificationManager.Notify(NOTIFICATION_ID, builder.Build());

The issues are:

When the notification "popup" appears, the title and content are there but the image is not.

When viewing the notification by pulling down / revealing the notifications, the image is there but the colour is wrong. It is kind of purple rather than red. However, if the app is in the background when the notification arrives, the icon is the correct colour (the icon still doesn't appear in the "popup" message)


I am using the CrossGeeks FirebasePushNotificationPlugin.

dotnet-xamarin
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You can change another nuget package to make a test:Xamarin.Firebase.Messaging, If you have same issue, If you do not have this issue after change nuget packages, it is related to the CrossGeeks FirebasePushNotificationPlugin, you can open a issue in the github directly.


0 Votes 0 ·

But isn't NotificationCompat.Builder from AndroidX.Core.App? I didn't think creating and publishing a notification had anything to do with the Firebase plugin?

Changing to Xamarin.Firebase.Messaging will require other code changes, won't it? E.g.
CrossFirebasePushNotification.Current.OnNotificationReceived += Current_OnNotificationReceived;

Are you saying that the code I have for creating the notification is correct?

0 Votes 0 ·

Are you saying that the code I have for creating the notification is correct?

Code is correct, but normally the icon will be grey, it will not change from red to purple, that is weird, NotificationCompat.Builder comes from androidx.core.app.

0 Votes 0 ·

Could you share this icon that I can make a test?

0 Votes 0 ·

0 Answers