1

基于https://developer.android.com/training/wearables/notifications/stacks.html,我构建了一个包含 3 个堆叠通知的示例,其中一个用于摘要。在 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 个单一通知

有没有办法在姜饼中将所有 3 个通知组合成一个通知?

4

0 回答 0