FCM Push Notifications are replacing when App is in Foreground

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



FCM Push Notifications are replacing when App is in Foreground



There is some web application for planning tasks. 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.



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();*/






try onesignal push its easy to customize, ho head ace
– Samwinishere Here
Aug 10 at 7:25





can you provide any links for implementation@SamwinishereHere
– vishnu
Aug 10 at 7:29





go to onesignal.com
– Samwinishere Here
Aug 10 at 10:26





Is your notificationData.getId() always unique ?
– Zealous
Aug 10 at 10:43





1 Answer
1



Android uses notification id to differentiate between the notifications. Therefore, itcan 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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard