【问题标题】:Grouping of Notifications not working in Android 8.1通知分组在 Android 8.1 中不起作用
【发布时间】:2018-06-08 14:28:16
【问题描述】:

我正在使用 FCM 在 8.1 版本的 Android 设备上发送通知。 我正在尝试实现通知的分组,我已经实现了。

每当第一个通知出现在状态栏中并且第二个通知到达时,第一个通知就会消失。从病房的第二个通知开始,所有通知都按预期显示在组中。

如何解决?

在下面发布代码截图。

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");

        }

【问题讨论】:

    标签: push-notification notifications android-notifications android-8.0-oreo android-8.1-oreo


    【解决方案1】:

    如果您使用相同的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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-02
      • 1970-01-01
      相关资源
      最近更新 更多