当应用程序在后台运行时,FCM无法显示弹出窗口 [英] FCM Cannot show pop up when app in the background
问题描述
如果fcm消息包含"notification"部分,并且应用程序处于后台,则将通知发送到系统托盘,并提供其他意图的数据.
If fcm message contains "notification" section and app is in the background, Notifications delivered to the system tray and data in extras of the intent.
问题是我无法更改此通知的重要性,并且它们始终不显示弹出窗口. 我为api 26+修复了此问题,我用
The problem is that I cannot change Importance for this notifications and they always do not show the popup. I fixes this problem for api 26+, i added Notification channel with
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将消息传递到
But for the api 25- i cannot find the solutions. The one suggestions are to remove "notification" section and leave only "data", this will allow fcm deliver messages to
onMessageReceived(RemoteMessage remoteMessage)
当应用程序在后台/前景中时,我将能够显示我的自定义通知.
when app is in background/foreground and I will be able to show my custom notifications.
推荐答案
我发现的最佳解决方案是仅使用Data
有效负载并处理onMessageReceived
方法中的背景/前景消息,并显示您的自定义通知.
The best solution i have found is to use only Data
payload and handle both background/foreground messages inside onMessageReceived
method and show your custom notifications.
这篇关于当应用程序在后台运行时,FCM无法显示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!