如何创建一组前台通知?

cod*_*per 5 android android-notifications android-fragments kotlin android-support-library

我正在开发一个 Android 应用程序,它有两个前台服务,并希望将通知分组到一个组中。有可能这样做吗?我已使用NotificationCompat.Builder setGroup(String groupKey) 启用组通知,但它不起作用。

通知助手.kt

enum ChannelType{ ID1, ID2} 

fun getNotificationChannelID(context: Context, channelType: ChannelType) : String? {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                val channelID = channelType.channelID
                val description = channelType.reourceID
                val channel = NotificationChannel(channelID, description,
                        NotificationManager.IMPORTANCE_HIGH);
                val mNotificationManager = mContext.getSystemService(Context.NOTIFICATION_SERVICE)
                        as android.app.NotificationManager
                mNotificationManager.createNotificationChannel(channel)
                return channelID
            }
            return null;
        }

fun createBuilder(context: Context, channelId: String, title: String, content: String,
                          ongoing: Boolean, autoCancel: Boolean,
                          style: NotificationCompat.Style, @DrawableRes icon: Int,
                          priority: Int, vibratePattern: LongArray): NotificationCompat.Builder {

           val builder = NotificationCompat.Builder(context, channelId)
            builder.setSmallIcon(icon)
                    .setContentTitle(title)
                    .setContentText(content)
                    .setAutoCancel(autoCancel)
                    .setOngoing(ongoing)
                    .setGroup(GROUP_KEY_NOTIF)
                    .setStyle(style)
                    .setGroupSummary(true)
            return builder

        }
    }
Run Code Online (Sandbox Code Playgroud)

来自服务 1

onStartCommand() {
    var channelID = getNotificationChannelID(context, ChannelType.ID1)
   startForeground(NOTIFICATION_ID1,createBuilder(context,
                                              channelID,
                                              "title",
                                              "description",
                                              ongoing = false,
                                              autocancel = true,
                                              someIcon,
                                              BigTextStyle,
                                               priority, vibratePattern )
                                               .build());
}   

Run Code Online (Sandbox Code Playgroud)

从服务 2

onStartCommand() {
    var channelID = getNotificationChannelID(context, ChannelType.ID1)
   startForeground(NOTIFICATION_ID1,createBuilder(context,
                                              channelID,
                                              "title",
                                              "description",
                                              ongoing = false,
                                              autocancel = true,
                                              someIcon,
                                              BigTextStyle,
                                              priority, vibratePattern)
                                               .build());
}   

Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?我也设置了ongoingfalse结果还是没有变化。

提前致谢。