繁体   English   中英

如何在 AndroidManifest 中使用自定义图标作为 FCM 默认通知图标 - Maui

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

按照 de FCM 文档,在 AndroidManifest 中设置了默认通知图标,但我想使用自定义图标作为 com.google.firebase.messaging.default_notification_icon。 我已经在带有 Build Action = MauiIcon 的 OnMessageReceived 方法中有了这个图标:

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

现在我想在 AndroidManifest 中使用这个“appicon”(替换 ic_dialog_alert):

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

我试过:android:resource="@mipmap/appicon" 但不起作用。

如何使用自定义图标作为 AndroidManifest 中的 default_notification_icon? 在毛伊岛可以吗? 或者我必须选择给出的 android:drawable/ 选项之一吗?

谢谢!

我的解决方案:

我创建了一个可绘制文件夹:Platforms/Android/Resources/drawable 并将图标的 BuildAction 设置为 AndroidResource。

在 AndroidManisfest 我能够得到图标:

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

我在 Platforms.Android.Resources 下创建了 drawable 文件夹。 然后,我使用 MauiImage 构建操作添加了一个名为 success.png 的 png 图像。 我没有编辑或向 AndroidManifest 文件添加任何内容。

notification.SetSmallIcon(Resource.Drawable.success);

如果你想添加一个通知图标,然后创建一个 drawable 文件夹 - Platforms/Android/Resources/drawable - 并在其中上传一个图标图像。 然后添加如下通知代码。

 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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM