Created
August 29, 2025 02:52
-
-
Save rainbow23/fb7071f0556d60be18d4c6d2dc3f0b80 to your computer and use it in GitHub Desktop.
Grouped notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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