Skip to content

Instantly share code, notes, and snippets.

@rainbow23
Created August 29, 2025 02:52
Show Gist options
  • Save rainbow23/fb7071f0556d60be18d4c6d2dc3f0b80 to your computer and use it in GitHub Desktop.
Save rainbow23/fb7071f0556d60be18d4c6d2dc3f0b80 to your computer and use it in GitHub Desktop.
Grouped notification
static final String CHANNEL_ID = "orders";
static final String GROUP_KEY = "group_orders";
void postGroupedNotifications(Context ctx) {
NotificationManager nm = ctx.getSystemService(NotificationManager.class);
if (Build.VERSION.SDK_INT >= 26) {
NotificationChannel ch = new NotificationChannel(
CHANNEL_ID, "Orders", NotificationManager.IMPORTANCE_DEFAULT);
nm.createNotificationChannel(ch);
}
Notification child1 = new NotificationCompat.Builder(ctx, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("注文 #1001")
.setContentText("出荷準備中")
.setGroup(GROUP_KEY)
.build();
Notification child2 = new NotificationCompat.Builder(ctx, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("注文 #1002")
.setContentText("支払い確認済み")
.setGroup(GROUP_KEY)
.build();
Notification summary = new NotificationCompat.Builder(ctx, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("注文の更新(2)")
.setStyle(new NotificationCompat.InboxStyle()
.addLine("注文 #1001: 出荷準備中")
.addLine("注文 #1002: 支払い確認済み")
.setSummaryText("ショップ名"))
.setGroup(GROUP_KEY)
.setGroupSummary(true)
.build();
nm.notify(1001, child1);
nm.notify(1002, child2);
nm.notify(9999, summary);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment