https://developer.android.com/training/wearables/notifications/stacks.htmlに基づいて、3 つの通知がスタックされた例を作成しました。そのうちの 1 つは要約用です。API > 14 のデバイスでは問題なく動作しますが、2.3 デバイスでは 3 つの通知すべてが個別に表示されます。
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("johndoe@gmail.com"))
.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);
}
}
ジンジャーブレッドの結果は
ジンジャーブレッドで 3 つの通知すべてを 1 つの通知にグループ化する方法はありますか?