androidnotificationsandroid-notificationswear-osandroid-wear-notification

Stacked Wear notification shown on phone too


I have 1 summary-notification and serveral stacked notifications. For some reason the stacked notifications are not only shown on the Andrid Wear device but also on the phone. According to the documentation Stacking Notifications they should only display on the watch. NotificationBuilder.setGroup is, of cause, set to the same value and only the summary has .setSummary(true).

Details: http://marcuswolschon.blogspot.de/2015/05/implementing-k9-mail-wear-support.html

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


Solution

  • Replace NotificationManager with NotificationManagerCompat

    Use 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

    Use 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