简体   繁体   English

当App位于前台时,FCM推送通知将被替换

[英]FCM Push Notifications are replacing when App is in Foreground

There is some web application for planning tasks. 有一些用于计划任务的Web应用程序。 If one task is added, Notification will send to the app with some task details. 如果添加了一项任务,则通知将发送一些任务详细信息到应用程序。 If the second task is added, First notification is replaced with the first notification. 如果添加了第二个任务,则第一个通知将替换为第一个通知。 only one notification is displaying that is the second one. 仅显示一个通知,即第二个。

when an app is in the background, 2 notifications are showing. 当应用在后台运行时,将显示2条通知。

But an app is in the foreground only one notification is displaying. 但是一个应用程序位于前台,仅显示一个通知。 Please help me. 请帮我。

Any help would be appreciated. 任何帮助,将不胜感激。

This is my code for notifications when an app is in the foreground. 这是我在前台运行应用程序时用于通知的代码。

if (!NotificationUtils.isAppIsInBackground(getApplicationContext())){
            Intent intent = new Intent(Config.PUSH_NOTIFICATION);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
            intent.putExtra("Plan","fromFCM");
            broadcastManager.sendBroadcast(intent);
            Bitmap bitmapIcon = BitmapFactory.decodeResource(getResources(), R.drawable.notify_app_icon);
            PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
            NotificationCompat.Builder notificationBulder = new NotificationCompat.Builder(this);
            notificationBulder.setContentTitle(notificationData.getTitle());
            notificationBulder.setContentText(notificationData.getTextMessage());
            notificationBulder.setSmallIcon(R.drawable.notify_app_icon);
            notificationBulder.setLargeIcon(bitmapIcon);
            notificationBulder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationData.getTextMessage()));
            notificationBulder.setAutoCancel(true);
            //notificationBulder.setSmallIcon(R.mipmap.ic_launcher);
            notificationBulder.setContentIntent(pendingIntent);
            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            if (notificationManager != null) {
                notificationManager.notify(notificationData.getId(), notificationBulder.build());
           /* Plan_Details plan_details = new Plan_Details();
            plan_details.refreshPlan();*/

            }

Android uses notification id to differentiate between the notifications. Android使用通知ID来区分通知。 Therefore, it can not differentiate between the notifications and shows multiple notifications. 因此,它不能区分通知,而显示多个通知。

Use tag parameter in the notification payload. 在通知有效负载中使用tag参数。

{
    "notification" : {
        "title" : "Notification Title",
        "body" : "Notification Body",
        "tag" : "your_unique_tag"
    }
}

Identifier used to replace existing notifications in the notification drawer. 用于替换通知抽屉中现有通知的标识符。

If not specified, each request creates a new notification. 如果未指定,则每个请求都会创建一个新通知。

If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer. 如果已指定并且已显示具有相同标签的通知,则新通知将替换通知抽屉中的现有通知。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当应用处于前台时,无法接收FCM通知 - Not able to receive FCM notifications when app is in foreground 应用程序终止时的 FCM 推送通知 FLUTTER - FCM push notifications FLUTTER when app is terminated 当应用程序处于前台或后台时如何使用 FCM 处理通知 - How to handle notifications with FCM when app is in either foreground or background 当应用程序处于后台状态时,FCM多个推送通知无法正常工作 - FCM Multiple push notifications not working properly when app in background state 应用程序被杀死时是否可以接收 FCM 推送通知? - Is it possible to receive FCM push notifications when app is killed? FCM 推送通知仅在应用程序处于后台时显示 - FCM Push Notifications are only displayed when app is in background 使用Delphi处理应用不在前台时的Android Push通知 - Handling Android Push notifications when app is not in the foreground using Delphi Titanium-Android-当应用程序不在前台时,推送通知失败 - Titanium - Android - Push Notifications Fail When App Is Not In Foreground 当应用程序在后台(Titanium)时,Android 5上的推送通知未送达 - 但它确实在前台 - Push notifications on Android 5 not delivered when app in background (Titanium) - But it does in foreground FCM:我已使用FCM接收有关我的应用程序的通知。 当我的应用程序处于前台时,它将所有通知分组,但不将其组合到后台时 - FCM: I have used FCM to receive notification for my app. When my app is in foreground it groups all notifications but not when app is in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM