【问题标题】:FCM Push notifications does not show heads display on notification on top of screenFCM 推送通知不会在屏幕顶部的通知上显示头像
【发布时间】:2017-04-11 14:58:07
【问题描述】:

我们在 Android 和 iOS 中使用 Firebase 推送通知。使用 FCM REST API 调用发送推送。推送类型为notification,带有额外的data 节点。

这是一个示例有效载荷:

{ 
  "notification" : {
    "title": "title text",
    "body": "message body text",
    "sound": "default"
  },
  "data":  {
    "messageType": "xxx"
  },
  "to": "yyy",
  "priority": "high",
  "time_to_live": 0
}

当应用程序处于后台且手机处于开机状态时,此类推送通知不会显示抬头显示。 -- 通知只是添加到通知栏,但不会在屏幕顶部向用户显示。 -- 无论当前应用是否为全屏应用。

我尝试过并且正在工作的一个解决方案是转移到纯data 消息,我们不会发送任何notification 节点,而只会发送data 节点并编写代码来自己显示通知并设置通知在通知生成器对象上优先于 Max(即.setPriority(Notification.PRIORITY_MAX))。 但这似乎在 iOS 上存在问题,如果应用程序被用户杀死,data 仅推送不会接收/显示给用户。

那么有什么解决方法吗?任何适用于 Android 且不会破坏 iOS 的解决方案。

【问题讨论】:

  • @mallaudin 谢谢,但那是不同的。
  • 数据信息呢?
  • 相关问题(很遗憾也没有答案):stackoverflow.com/questions/41528315/…
  • @AamirAbro,but are not sneak peaked to user at the top of the screen 是什么意思?你也可以发布android代码吗?
  • @ArindamNayak 这意味着 id 不显示任何抬头显示。

标签: android firebase firebase-cloud-messaging


【解决方案1】:

对于 Android,您应该将 NotificationPriority 设置为 PRIORITY_HIGH 或 PRIORITY_MAX 以显示通知。有关详细信息,请参阅 Android NotificationNotification Priority

您应该使用常量而不是字符串来设置这些值。例如

{
  token,
  android: {
    notification:
    {
      title,
      body,
      // See https://developer.android.com/reference/android/app/Notification#PRIORITY_MAX.
      // This is deprecated in Android API level 26, but works for older versions.
      notification_priority: 2,
      // Always allow Android users to see the message in its entirety.
      // See https://developer.android.com/reference/android/app/Notification#VISIBILITY_PUBLIC
      visibility: 1
    }
  }
}

【讨论】:

  • 我认为你应该放一个字符串而不是一个int,否则你会得到这个错误: TypeError: notification.visibility.toUpperCase is not a function 所以我认为最好使用类似的东西: visibility : "public" or visibility:"2" 信息来源:firebase.google.com/docs/cloud-messaging/concept-options?hl=es
猜你喜欢
  • 2017-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多