Based on https://developer.android.com/training/wearables/notifications/stacks.html I built an example with 3 stacked notifications, one of them for summary. In devices with API > 14 it works just fine, but in 2.3 devices it shows all 3 notifications independently.
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
final String GROUP_KEY_EMAILS = "group_key_emails";
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification summaryNotification = new NotificationCompat.Builder(this)
.setContentTitle("2 new messages")
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(new NotificationCompat.InboxStyle()
.addLine("Alex Faaborg Check this out")
.addLine("Jeff Chang Launch Party")
.setBigContentTitle("2 new messages")
.setSummaryText("[email protected]"))
.setContentIntent(pendingIntent)
.setGroup(GROUP_KEY_EMAILS)
.setGroupSummary(true)
.build();
notificationManager.notify(0, summaryNotification);
// Build the notification, setting the group appropriately
Notification notif = new NotificationCompat.Builder(this)
.setContentTitle("content title 1")
.setContentText("content text 1")
.setSmallIcon(R.drawable.ic_stat_social_mood)
.setContentIntent(pendingIntent)
.setGroup(GROUP_KEY_EMAILS)
.build();
// Issue the notification
notificationManager.notify(1, notif);
Notification notif2 = new NotificationCompat.Builder(this)
.setContentTitle("content title 2")
.setContentText("content text 2")
.setSmallIcon(R.drawable.ic_stat_social_mood)
.setContentIntent(pendingIntent)
.setGroup(GROUP_KEY_EMAILS)
.build();
notificationManager.notify(2, notif2);
}
}
The result in Gingerbread is
Is there any way to group all 3 notifications into a single one in gingerbread?