android - Stacked Wear 通知也显示在手机上

标签 android notifications android-notifications wear-os android-wear-notification

我有 1 个摘要通知和多个堆叠通知。 由于某种原因,堆叠通知不仅显示在 Andrid Wear 设备也可以放在手机上。 根据文档 Stacking Notifications 它们应该只显示在 watch 上。 NotificationBuilder.setGroup 当然设置为相同的值,并且只有摘要具有 .setSummary(true)。

详细信息: http://marcuswolschon.blogspot.de/2015/05/implementing-k9-mail-wear-support.html

代码: https://github.com/k9mail/k-9/blob/73ec00b43db81038805999f5642961ae9005d6bc/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java#L4941

最佳答案

NotificationManager 替换为 NotificationManagerCompat

使用NotificationManager

private void send() {
    Notification notification1 =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("News1")
                    .setGroup("News")
                    .setContentText("Text")
                    .build();

    Notification notification2 =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("News2")
                    .setGroup("News")
                    .setContentText("Text2")
                    .build();

    NotificationManager notificationManager = (NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);

    notificationManager.notify(1 , notification1);
    notificationManager.notify(2 , notification2);

    Notification Summary = new NotificationCompat.Builder(this)
            .setContentTitle("2 new News")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText("Text2")
            .setGroup("News")
            .setGroupSummary(true)
            .build();

    notificationManager.notify(-1 , Summary);
}

enter image description here

使用NotificationManagerCompat

private void send() {
    Notification notification1 =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("News1")
                    .setGroup("News")
                    .setContentText("Text")
                    .build();

    Notification notification2 =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("News2")
                    .setGroup("News")
                    .setContentText("Text2")
                    .build();

    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);

    notificationManager.notify(1 , notification1);
    notificationManager.notify(2 , notification2);

    Notification Summary = new NotificationCompat.Builder(this)
            .setContentTitle("2 new News")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText("Text2")
            .setGroup("News")
            .setGroupSummary(true)
            .build();

    notificationManager.notify(-1 , Summary);
}

enter image description here

关于android - Stacked Wear 通知也显示在手机上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30108156/

相关文章:

java - 使用 Joda Time 时无法生成启用了混淆器的签名 APK

android - 如何从服务中获取值(value)到android中的 Activity ?

push-notification - putExtra 使用挂起意图不起作用

java - 从 native 代码调用另一个包的静态 java 方法

android - Zebra Android Printing with v2.8.2148 图像打印为字符串而不是像素

php - 实时实时通知 Jquery PHP

android - 如何设置动态小图标通知

Android bundle 通知行为

java - setSmallIcon() 和 setLargeIcon() 在 Android 通知中不起作用

android - TimePicker Android 自定义小时