【问题标题】:FCM Cannot show pop up when app in the background当应用程序在后台时,FCM 无法显示弹出窗口
【发布时间】:2018-11-11 14:24:28
【问题描述】:

如果 fcm 消息包含“通知”部分并且应用程序在后台,则将通知传递到系统托盘和 Intent 的附加内容中的数据。

问题是我无法更改此通知的重要性,并且它们始终不显示弹出窗口。 我为 api 26+ 解决了这个问题,我用

添加了通知通道
int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel channel = new NotificationChannel(getString(R.string.default_notification_channel_id), name, importance);

在清单中

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

但是对于 api 25- 我找不到解决方案。一个建议是删除“通知”部分并仅保留“数据”,这将允许 fcm 将消息传递给

onMessageReceived(RemoteMessage remoteMessage)

当应用程序处于后台/前台时,我将能够显示我的自定义通知。

【问题讨论】:

  • 您想更改应用在后台时发送的通知的重要性吗?
  • @wonsuc 是的,因为它们在没有弹出窗口的情况下显示。
  • 仅使用Data有效载荷发送的方式如何?这种方式不适合你吗?
  • @wonsuc 是的,我想过这个。但我不明白为什么 fcm 允许您在清单更改默认通知图标/颜色/通知通道中但不允许更改重要性。
  • 如果你真的需要使用Notification有效载荷发送,priority的选项名称与Importance功能相同。但是当payload为Notification类型时,默认priority选项为“high”。尝试将priority 选项设置为“高”。详细文档是here

标签: android firebase firebase-cloud-messaging


【解决方案1】:

我发现的最佳解决方案是仅使用 Data 有效负载并处理 onMessageReceivedmethod 内的背景/前台消息并显示您的自定义通知。

【讨论】:

    猜你喜欢
    • 2019-10-30
    • 2013-07-03
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 2023-03-25
    • 2017-06-25
    相关资源
    最近更新 更多