【问题标题】:How to display the image in the notification如何在通知中显示图像
【发布时间】:2022-02-14 09:22:31
【问题描述】:

我最近在我的应用程序中使用了 FirebasePushNotificationPlugin,一切都很好...... 但是当我发送通知时,图像不显示,所有其他文本都显示 我已经搜索并尝试过但无济于事: 这是该工具的链接: https://github.com/CrossGeeks/FirebasePushNotificationPlugin 这是我的代码: 安卓:

[Application]
public class MainApplication : Application
{
    public MainApplication(IntPtr handle, JniHandleOwnership transer) : base(handle, transer)
    {
    }

    public override void OnCreate()
    {
        base.OnCreate();

        //Set the default notification channel for your app when running Android Oreo
        if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
        {
            //Change for your default notification channel id here
            FirebasePushNotificationManager.DefaultNotificationChannelId = "GeneralChannel";
            //Change for your default notification channel name here
            FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            FirebasePushNotificationManager.DefaultNotificationChannelImportance = NotificationImportance.Max;
        }
        //If debug you should reset the token each time.
#if DEBUG
            FirebasePushNotificationManager.Initialize(this, true);
#else
            FirebasePushNotificationManager.Initialize(this, false);
#endif

        //Handle notification when app is closed here
        CrossFirebasePushNotification.Current.OnNotificationReceived += Current_OnNotificationReceived;

    }

    private void Current_OnNotificationReceived(object source, FirebasePushNotificationDataEventArgs e)
    {
       
    }
}

主活动:

FirebasePushNotificationManager.ProcessIntent(this, Intent);

在后端我使用了 FireBase 管理插件:

public async void SendToAllUser(Notification notification, Dictionary<string, string> MsgData)
        {
            var message = new Message()
            {
                Data = MsgData,
                Topic = "all",
                Notification = notification,
                Apns = new ApnsConfig
                {
                    Aps = new Aps
                    {
                        ContentAvailable = true,
                        MutableContent = true 
                    }
                }
            };
            string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
            Console.WriteLine("Successfully sent message: " + response);
        }

通知控制器:

[HttpPost("UserName={UserName}&Password={Password}&Key={Key}&Value={Value}")]
        public ActionResult<Notification> SendToAllDevice(string UserName, string Password, string Key, string Value, Notification notification)
        {
            int UserRole = URole.CheckUserRolee(UserName, Password);
            if (UserRole != 1)
            {
                return StatusCode(403);
            }
            var Dataa = new Dictionary<string, string>() { { Key, Value } };
            SendFCMessage.SendToAllUser(notification, Dataa);
            return Ok();
        }

【问题讨论】:

    标签: c# xamarin xamarin.forms xamarin.android


    【解决方案1】:

    确保您在 FCM 控制台中添加键和值(图像 url)并使用您编写的服务进行处理。

    可以参考这个问题https://docs.microsoft.com/en-us/answers/questions/541284/xamarin-forms-firebase-notification-ui.html

    这里还有一个示例:https://github.com/xamarin/monodroid-samples/tree/main/Firebase/FCMNotifications/FCMNotifications

    编辑:

     <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/notification_channel_id" />
    

    【讨论】:

    • 我在通知 Receve outPut 时使用了 plugin.FirebasePushNotification 写道:[FirebaseMessaging] 无法记录事件:缺少分析库 [FirebaseMessaging] AndroidManifest 中缺少默认通知通道元数据。将使用默认值。 [FirebaseMessaging] 无法记录事件:缺少分析库
    • 正确设置元名称,以便可以像上面显示的那样识别默认通知通道
    • 谢谢你的回答但我仍然面临同样的问题而且它不显示图像我最近将此行添加到 Manafist 但是图像仍然没有显示并且这一行出现在输出中:[FirebaseMessaging] Unable to log event: analytics library is missing
    • 我补充说: 消息“缺少默认通知通道”不再出现但通知中的图像仍然不显示我不知道为什么?输出:[FirebaseMessaging] 无法记录事件:缺少分析库
    猜你喜欢
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多