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 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" />
I created the drawable folder under Platforms.Android.Resources. I then added a png image called success.png with MauiImage build action. I did not edit or add anything to the AndroidManifest file.
notification.SetSmallIcon(Resource.Drawable.success);
If you want to add a notification icon, then create a drawable folder— Platforms/Android/Resources/drawable
—and upload an icon image inside of it. Then add the code for notifications like below.
private void CreateNotificationChannel()
{
var channelId = $"{PackageName}.general";
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
notificationManager.CreateNotificationChannel(channel);
//code for notification icon
FirebaseCloudMessagingImplementation.SmallIconRef = Resource.Drawable.notificationicon;
FirebaseCloudMessagingImplementation.ChannelId = channelId;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.