首页 > 解决方案 > 当应用程序在后台时,FCM 无法显示弹出窗口

问题描述

如果 fcm 消息包含“通知”部分并且应用程序在后台,则通知将传递到系统托盘和意图的额外数据。

问题是我无法更改此通知的重要性,并且它们始终不显示弹出窗口。我为 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)

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

标签: androidfirebasefirebase-cloud-messaging

解决方案


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


推荐阅读