Группировка уведомлений не работает в Android 8.1 - PullRequest
0 голосов
/ 08 июня 2018

Я использую FCM для отправки уведомлений на Android-устройство версии 8.1.Я пытаюсь выполнить группировку уведомлений, и я достиг этого.

Всякий раз, когда первое уведомление находится в строке состояния, а второе приходит, первое уведомление исчезает.Со второго уведомления на палатах все уведомления показываются в группе, как и ожидалось.

Как ее решить?

Почтовый код Snipper ниже.

if ("FirstTime".equals(new SharedPrefsOperations(this).getPreferencesData("ActiveNotifs"))) {

                    // I AM EXECUTING THIS ONLY AT FIRST TIME , WHEN THE FIRST NOTIFICATION ARRIVES.

                    String tempData = new SharedPrefsOperations(this).getPreferencesData("ActiveNotifs");

            Notification notification = new NotificationCompat.Builder(this, "MYAPP")
                    .setSmallIcon(R.mipmap.ic_static_notif)
                    .setContentTitle(content.getTitle())
                    .setContentText(tempMsg)
                    .setAutoCancel(true)
                    .setContentIntent(pendingIntent)
                    .setGroup(notifGroup)
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setChannelId(channel_id)
                    .setStyle(inboxStyle)
                    .setGroupSummary(true)
                    .build();

            notificationManager.notify(id, notification);
            new SharedPrefsOperations(this).storePreferencesData("ActiveNotifs", "1");

        } else {
                     // I AM EXECUTING THIS FROM SECOND NOTIFICATION ONWARDS
                    String tempData = new 

        SharedPrefsOperations(this).getPreferencesData("ActiveNotifs");


            Notification notification = new NotificationCompat.Builder(this, "MYAPP")
                    .setSmallIcon(R.mipmap.ic_static_notif)
                    .setContentTitle(content.getTitle())
                    .setContentText(tempMsg)
                    .setAutoCancel(true)
                    .setContentIntent(pendingIntent)
                    .setGroup(notifGroup)
               .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setChannelId(channel_id)
                    .setStyle(inboxStyle)
                    .build();

            notificationManager.notify(id, notification);
            new SharedPrefsOperations(this).storePreferencesData("ActiveNotifs", "1");

        }

1 Ответ

0 голосов
/ 07 января 2019

Если вы используете тот же id для уведомления, он не будет работать.Вам нужно использовать другой id для этого

Обновление Выше Android 8.0 (Oreo) Каналы уведомлений являются обязательными.Так что добавьте канал уведомлений вот так.Это должно быть сделано до уведомления.

 val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

// Android O requires a Notification Channel.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    val name = context.getString(R.string.app_name)
    // Create the channel for the notification
    val mChannel = NotificationChannel("channel_id_sms", name, NotificationManager.IMPORTANCE_DEFAULT)
    // Set the Notification Channel for the Notification Manager.
    mNotificationManager.createNotificationChannel(mChannel)
}
...