Search code examples
c#androidfirebase-cloud-messagingmaui.net-maui

How to use a custom icon as FCM default notification icon in AndroidManifest - Maui


Following de FCM documentation a have set a default notification icon in AndroidManifest but I want to use a custom icon to be the com.google.firebase.messaging.default_notification_icon. I already have this icon in the OnMessageReceived method with Build Action = MauiIcon:

var notificationBuilder = new NotificationCompat.Builder(this, MainActivity.CHANNEL_ID)
                                  .SetSmallIcon(Giki.Maui.Resource.Mipmap.appicon)
                                  .SetContentTitle(titleNotification)
                                  .SetContentText(messageBody)
                                  .SetAutoCancel(true)
                                  .SetContentIntent(pendingIntent);

Now I want to use this "appicon" in the AndroidManifest (replace the ic_dialog_alert):

<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@android:drawable/ic_dialog_alert" />

I tried: android:resource="@mipmap/appicon" but doesn't work.

How can I use a custom icon as the default_notification_icon in AndroidManifest? Is it possible in Maui? Or do I have to choose one of the android:drawable/ options given?

Thanks!


Solution

  • Solution for me:

    I've created a drawable folder: Platforms/Android/Resources/drawable and set the BuildAction of the icon to AndroidResource.

    In the AndroidManisfest I was able to get the icon:

    <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/iconnotifi" />