FCM推送通知不会在屏幕顶部的通知上显示头部显示

Aam*_*bro 5 android firebase firebase-cloud-messaging

我们在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
}
Run Code Online (Sandbox Code Playgroud)

当应用程序处于后台并且手机处于打开状态时,此类推送通知不显示抬头显示. - 通知只会添加到通知栏中,但不会在屏幕顶部潜入峰值. - 无论当前的应用程序是否是全屏应用程序.

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

那么有什么解决方法吗?任何适用于Android的解决方案,但也不会破坏iOS.

pir*_*pir 0

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

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

{
  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
    }
  }
}
Run Code Online (Sandbox Code Playgroud)