android - 当应用程序在后台时,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)
当应用程序处于后台/前台时,我将能够显示我的自定义通知。
解决方案
我发现的最佳解决方案是仅使用Data
有效负载并处理方法内部的背景/前台消息onMessageReceived
并显示您的自定义通知。
推荐阅读
- sql-server - 转换 SQL 列定义和默认值
- asp.net - 为什么这个 if else 语句有效,但这个 Switch 语句无效
- java - 在 Jython 2.5 中同时执行多个功能
- asp.net-identity - 调试 IdentityServer4 数据存储
- apache-spark - 高效读取 Spark 中的嵌套拼花列
- c# - 找不到类型或命名空间名称“MyApplication”(您是否缺少 using 指令或程序集引用?)
- tensorflow - 自定义 Keras binary_crossentropy 损失函数不起作用
- html - 读取值
有角度的 - java - 为什么 java.lang.reflect.Proxy 需要声明检查的异常,而正常的方法调用不需要?
- scala - 定义元素的顺序