【问题标题】:Firebase Push Notification how to set icon? Using Admin SDK in .NETFirebase 推送通知如何设置图标?在 .NET 中使用管理 SDK
【发布时间】:2020-05-02 13:34:14
【问题描述】:

基本上我想使用 Firebase 在推送通知上设置图标。我正在使用他们的 Firebase Admin .NET SDK。除了一个小细节之外,它实际上工作得很好,我无法设置图标。利用类FirebaseAdmin.Messaging.Message,然后指定属性Token,然后指定Notification对象(具有三个属性):

  1. 身体
  2. 图片网址
  3. 标题

设置这些后,推送通知工作正常,但ImageUrl 是带有消息而不是图标的实际图像。我想设置图标。浏览完文档后,我注意到Message 有一个名为Webpush 类型为WebpushConfig 的属性,它有一个Notification 类型为WebpushNotification 的属性,并且繁荣!它们在那里,有一堆设置,如平铺、身体、振动等,但我真正想要的设置在那里 Icon。不幸的是,为WebpushNotification 设置属性似乎没有任何作用。这是我的代码。

    public async Task Push(string token)
    {
        await messaging.SendAsync(new Message() { 
            Token = token,
            Notification = new Notification() {
              //Title = "This Title works",
              //Body = "This body works",
              //ImageUrl = "someUrlThatWorks"
            },
            Webpush = new WebpushConfig()
            {
                Notification = new WebpushNotification
                {
                    Title = "This title does not work",
                    Body = "This body does not work",
                    Icon = "thisIconDoesNotWork.png"
                }
            }
        });
    }

基本上只有FirebaseAdmin.Messaging.Notification work.的三个属性

但是FirebaseAdmin.Messaging.WebpushNotification 的属性我无法开始工作,我只想要那里的Icon

这里是Docs

谢谢。

【问题讨论】:

    标签: c# .net firebase push-notification firebase-cloud-messaging


    【解决方案1】:

    将以下内容添加到 AndroidManifest.xml 文件中

    <!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_stat_ic_notification" />
    <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
         notification message. -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />
    
    

    【讨论】:

    • 或在您发送通知之前设置图标属性:var msg = new Message() { Token = token, Notification = new Notification() { Body = notificationBody, Title = title, }, Android = new AndroidConfig() { Notification = new AndroidNotification() { ClickAction = "FLUTTER_NOTIFICATION_CLICK", Icon= "ic_launcher" } }, };
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 2019-10-26
    • 2019-02-02
    • 1970-01-01
    • 2020-03-21
    相关资源
    最近更新 更多