Android O上捆绑通知的双重通知声音

jam*_*ael 5 notifications android android-8.0-oreo

我正在尝试实现捆绑通知.经过大量的教程和博客后,我知道我必须生成两个通知.一个是定期通知,另一个是摘要通知.我按照这些博客文章中的说明进行了跟踪.一切似乎都有效.但是我在Android O上的每个通知都会收到双重通知声音.无论如何,我无法修复此问题.我搜索过其他人可能面临的任何类似问题.但我没有找到任何有用的东西.

以下是生成通知的一些代码段

定期通知

public Notification getSmallNotification(String channelId, String title, String body, Intent intent) {
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    mContext,
                    ID_SMALL_NOTIFICATION,
                    intent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, channelId);
    builder.setTicker(title)
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(true)
            .setContentIntent(resultPendingIntent)
            .setContentTitle(title)
            .setContentText(body)
            .setSmallIcon(R.drawable.ic_gw_notification)
            .setColor(ContextCompat.getColor(mContext, R.color.color_bg_splash))
            .setGroup(channelId);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        builder.setDefaults(Notification.DEFAULT_SOUND);
    }

    Notification notification = builder.build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    return notification;
}
Run Code Online (Sandbox Code Playgroud)

摘要通知

public Notification getSummaryNotification(String channelId, String title, String body) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, channelId)
            .setContentTitle(title)
            .setContentText(body)
            .setSmallIcon(R.drawable.ic_gw_notification)
            .setColor(ContextCompat.getColor(mContext, R.color.color_bg_splash))
            .setShowWhen(true)
            .setGroup(channelId)
            .setGroupSummary(true);

    return builder.build();
}
Run Code Online (Sandbox Code Playgroud)

然后我同时称这两个功能

notification = gwNotificationManager.getSmallNotification(channelId, title, body, intent);
notificationUtils.getManager().notify(channelId, (int) uniqueId, notification);
Notification summaryNotification = gwNotificationManager.getSummaryNotification(channelId, groupTitle, groupBody);
notificationUtils.getManager().notify(channelId, 0, summaryNotification);
Run Code Online (Sandbox Code Playgroud)

如何解决双音问题?任何帮助将非常感激!

Ale*_*kov 0

我在 Android 8+ 上遇到了同样的问题,我通过创建重要性较低的附加通道来解决它:

manager.createNotificationChannel(new NotificationChannel(silentChannelId, name, NotificationManager.IMPORTANCE_LOW));
Run Code Online (Sandbox Code Playgroud)

然后使用此通道创建摘要通知:

new NotificationCompat.Builder(context, silentChannelId)
Run Code Online (Sandbox Code Playgroud)