FCM无法在后台应用时弹出

时间:2018-06-01 12:30:56

标签: android firebase firebase-cloud-messaging

如果fcm消息包含"通知"部分和应用程序在后台,通知传递到系统托盘和意图附加内容中的数据。

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

添加了Notification channel
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-我找不到解决方案。一个建议是删除&#34;通知&#34;部分只留下&#34;数据&#34;,这将允许fcm传递消息

onMessageReceived(RemoteMessage remoteMessage)

当app处于后台/前台时,我将能够显示自定义通知。

1 个答案:

答案 0 :(得分:1)

我找到的最佳解决方案是仅使用Data有效负载并处理onMessageReceived方法中的后台/前台消息并显示您的自定义通知。