Android : as grouped by the type of notification?

on Thursday, December 4, 2014


I have 2 types of notifications. such as "hello world" and "goodbye world". and here comes from the server "hello world" - a notification appears. comes again "hello world" - notification does not appear as an old stated that the two of them. comes "as the world" and now the two notifications. one with the number two with a second number one. How is that done?


now all each notification is displayed separately:



private static void generateNotification(Context context, String message) {
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

Intent intent = new Intent(context,MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_stat_gcm)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_gcm))
.setTicker("New message")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle("message")
.setContentText(message);

Notification notification = builder.build();
nm.notify(id++,notification);
}


method call is triggered in the method of service:



@Override
protected void onMessage(Context context, Intent intent) {
String message = intent.getStringExtra("content");
generateNotification(context, message);
}

0 comments:

Post a Comment