Reputation: 931
I have incorporated GCM notification, but it overwrites the existing, then by suggestion given in
this link i used and got it, but it is updating as multiple notifications, need to achieve like this image -
Here i was unable to achieve this type in multiple lines. I am trying with BigNotify not with styles and expand but i need to stack the notification as declared in Summarize notification guide
To the least case I am trying to achieve that 5 messages from 3 chats as summarizing the notification, any work around on this ?
Upvotes: 1
Views: 667
Reputation: 931
I finally ended up customizing it to achieve it by this code.
int notificationId = Prefs.getIntPref(context, Prefs.NEWLEAD_NOTIFY, 0);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putExtra("message",message);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_CANCEL_CURRENT);
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.logo);
array_messages.add(message);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setTicker("My product")
.setSmallIcon(icon)
.setLargeIcon(largeIcon)
.setWhen(System.currentTimeMillis())
.setContentTitle("My product")
.setContentIntent(resultPendingIntent)
.setAutoCancel(true).setDefaults(Notification.FLAG_AUTO_CANCEL).setDefaults(Notification.DEFAULT_SOUND)
.setDefaults(Notification.DEFAULT_VIBRATE) ;
if(array_messages.size()==1)
builder.setContentText(message);
else
builder.setContentText(array_messages.size() +" Lead notifications");
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
if(array_messages.size()<=5) {
for (int i = 0; i < array_messages.size(); i++) {
inboxStyle.addLine(array_messages.get(i));
}
inboxStyle.setBigContentTitle("My Product");
inboxStyle.setSummaryText(array_messages.size() +" Lead notifications");
}
else {
for (int i = 0; i <= 5; i++) {
inboxStyle.addLine(array_messages.get(i));
}
inboxStyle.setBigContentTitle("My product");
inboxStyle.setSummaryText(array_messages.size() +" Lead notifications");
}
builder.setStyle(inboxStyle);
notificationManager.notify(0, builder.build());
notificationId = notificationId + 1;
Prefs.setIntPref(context, Prefs.NEWLEAD_NOTIFY, notificationId);
Upvotes: 2
Reputation: 931
I got the answer, tried like this
`
public static void pushNotification(Activity currentActivity, String title, String content[]){
NotificationManager nm = (NotificationManager) currentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(currentActivity.getBaseContext(), FileSharingActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(currentActivity);
stackBuilder.addParentStack(FileSharingActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
nm.notify(nextId++, new Notification.InboxStyle(new Notification.Builder(currentActivity.getBaseContext())
.setTicker("Ticker")
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setContentTitle("Content title")
.setContentText("Content text")
.setNumber(4)
.setContentIntent(resultPendingIntent))
.addLine("First Message")
.addLine("Second Message")
.addLine("Third Message")
.addLine("Fourth Message")
.setBigContentTitle("Here Your Messages")
.setSummaryText("+3 more")
.build());
}
`
Upvotes: 2