.netxamarin.formsmauiappicon

.Net Maui-Can't set my appicon as the push notification small icon for Android


I am trying to implement firebase push notifications on my .Net Maui app. When I try to set my appicon as the smallicon of the notification it is not recognised.code snippet

This is working in xamarin.forms. Can anyone please help me with this?


Solution

  • You can put the image in the Resources/Images folder in the MAUI. It is different between the Maui and Xamarin. Then change the wrong code to Resource.Drawable.appicon.

       var notificationBuilder = new NotificationCompat.Builder(this, MainActivity.ChannelID)
                    .SetSmallIcon(Resource.Drawable.appicon)
                    .SetContentTitle(title)
                    .SetContentText(messageBody)
                    .SetChannelId(MainActivity.ChannelID)
                    .SetPriority((int)NotificationPriority.High);
        
        var notificationManager = NotificationManagerCompat.From(this);
        notificationManager.Notify(MainActivity.NotificationID, notificationBuilder.Build());