Grouped notifications fire the same pending intent - android

I am grouping multiple notifications into one group, each notification has a different pending intent.
When any of the notifications in the group is clicked the same pending intent is fired (the one added to the last added notification).
What I was expecting is each notification should fire its own intent.
Summary notification:
NotificationCompat.Builder groupSummaryBuilder =
new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)
.setContentTitle("title")
.setContentText("message")
.setGroupSummary(true)
.setAutoCancel(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setGroup(GROUP_ID)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
Group notofications:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(message);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setGroup(GROUP_ID);
notificationBuilder.setAutoCancel(true);
What am I missing here?

Related

My FCM notification does not expand when the app is in background

I am implementing FCM to push notifications, but I am trying to expand the notification when the content of the notification is big.
It cannot be implemented when the app is in background
here is my code
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_new_logo).setTicker(title).setWhen(0)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_new_logo))
.setContentTitle("SuezApp")
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setStyle(new NotificationCompat.BigTextStyle().bigText(title))
.setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody()))
.setPriority(Notification.PRIORITY_MAX)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(notificationBuilder);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
How can I expand it when the app is in background?
Per the Firebase 9.4 release notes:
Expanded gestures are now supported for messages, allowing the Android UI to display multiple lines when the body of a notification exceeds a single line.
Make sure you are using Firebase 9.4 or higher as your dependency.

Push Notification with action button is not working

i have used the fcm for notification and its coming correctly, but when i try to add add buttons in notification its not showing.
my code
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("New Message From Film")
.setContentText(messageBody)
.setAutoCancel(true)
.addAction(R.drawable.pp, "Accept",pendingIntent)
.addAction(R.drawable.pp, "Reject",pendingIntent)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
You forgot to build use method build() in last
edited code
Builder
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("New Message From Film")
.setContentText(messageBody)
.setAutoCancel(true)
.addAction(R.drawable.pp, "Accept",pendingIntent)
.addAction(R.drawable.pp, "Reject",pendingIntent)
.setContentIntent(pendingIntent);
notification
final Notification notification = notificationBuilder.build();
mNotificationManager.notify(notificationId, notification);

setgroup() in notification not working

I'm tring to create notification group, this is my code:
// Build the notification, setting the group appropriately
Notification notif = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("New mail from " + 1)
.setContentText("cv")
.setSmallIcon(R.drawable.rh_logo)
.setStyle(new NotificationCompat.InboxStyle()
.addLine("Alex Faaborg Check this out")
.addLine("Jeff Chang Launch Party")
.setBigContentTitle("2 new messages")
.setSummaryText("johndoe#gmail.com"))
.setGroup(GROUP_KEY_EMAILS)
.setGroupSummary(true)
.build();
// Issue the notification
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(++NOTIFICATION_ID, notif);
When I run the app, and send notification messages, they do not show in group.
Can someone explain me what I need to change?
You have to create a group notification before creating your custom notification. Just like this:
NotificationCompat.Builder groupBuilder =
new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(content)
.setGroupSummary(true)
.setGroup("GROUP_1")
.setStyle(new NotificationCompat.BigTextStyle().bigText(content))
.setContentIntent(pendingIntent);
Do not forget setGroupSummary to true.
Then create your child notification which group value is same to groupBuilder's value。Here is "GROUP_1".
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_communication_invert_colors_on)
.setContentTitle(title)
.setContentText(content)
.setGroup("GROUP_1")
.setStyle(new NotificationCompat.BigTextStyle().bigText(content))
.setContentIntent(pendingIntent)
Finally use NoticationManagerCompat to notify them.
NotificationManagerCompat manager = NotificationManagerCompat.from(context);
manager.notify(GROUP_ID, groupBuilder.build());
manager.notify(id, builder.build());
Replace
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(++NOTIFICATION_ID, notif);
with
NotificationManagerCompat.from(mCtx).notify(++NOTIFICATION_ID,notif);
because you are using NotificationCompat
There is a strange behavior of notification. If you add autocancel notification group doesn't work, if you add setGroup or setGroupSummary. It will not work. Removing all that fixed the problem for me. Basically, you don't need to mention any group it will auto group. TESTED on Redmi 10 pr0, Poco x3 NFC, huawei device.
return new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_action_name)
.setContentTitle(title)
.setContentText(body)
.setStyle(new NotificationCompat.BigTextStyle().bigText(body))
.setPriority(NotificationCompat.PRIORITY_LOW);

Update Notification without Collasping notification drawer

i have a notification manager that launches an activity when clicked.
mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContent(remoteViews)
.setAutoCancel(false);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, Launch.class).putExtra("type", 0), 0);
mBuilder.setContentIntent(pendingIntent);
the function performed in this can also be be asynchronous depending on the users preference. I want to update the notification to an ongoing progress. something of this nature:
mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setContentTitle("Sending details")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setProgress(100, 0, true)
.setOnlyAlertOnce(true)
.setAutoCancel(false);
when the notification is selected. This is achieved but what i want to do is update the notification from the former to the later without having to first slide up the navigation drawer.
Try this..
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
you need NOTIFICATION_ID to updated the specific notification.
Please refer this

Android - How to Display Large Text in Notification

I need to implement a code for displaying large text with 200 characters in Notifications. Here i used following code but it shows single line.
Intent notificationIntent;
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(message)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);
notificationIntent = new Intent(context, Main.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pintent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pintent);
NotificationManager mNotifyMgr =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(1, mBuilder.build());
You can choose from different styles to use for the notification builder:
In your case I would use the NotificationCompat.BigTextStyle. More details can be found here.
Don't forget to import v4 support when using this.
In my application, notification message is static but can't show all sentense.
I solved with subText properties of notification.
Notification n = new Notification.Builder(this)
.setContentTitle("Job Tracker Application")
.setContentText("GPS is turned off.")
.setSubText("Please turn on in the settings.")
.setSmallIcon(R.drawable.app_icon)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build();
Another notification sample have show under the blogs.
http://www.objc.io/issue-11/android-notifications.html
https://capdroid.wordpress.com/tag/android-notification/
http://www.tutorialspoint.com/android/android_notifications.htm
You add a style for the the large text.
Notification notification = new NotificationCompat.Builder(this, CHANNEL_SYNC)
.setContentTitle(title)
.setSmallIcon(R.drawable.ic_sync)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setColor(getResources().getColor(R.color.colorPrimaryLight))
.setContentIntent(pendingIntent)
.build();

Categories

Resources