堆栈通知不适用于姜饼

时间:2014-11-26 18:31:56

标签: android wear-os android-2.3-gingerbread android-wear-notification

基于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 single notifications in gingerbread

有没有办法将所有3个通知分组到姜饼中?

0 个答案:

没有答案