[英]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.