我是一名有用的助手,可以为您翻译文本。
我正在尝试实现捆绑通知。经过大量教程和博客的学习,我了解到我必须生成两个通知,一个是常规通知,另一个是摘要通知。我按照这些博客文章中所述的一切去做,一切似乎都有效。但是在Android O上,每个通知都会产生双重通知声音。我无论如何都无法解决这个问题。我已经搜索了其他人可能遇到的类似问题,但没有找到任何有用的信息。
以下是生成通知的一些代码片段:
常规通知
然后我同时调用这两个函数。
我应该如何解决双声问题?非常感谢您的帮助!
我正在尝试实现捆绑通知。经过大量教程和博客的学习,我了解到我必须生成两个通知,一个是常规通知,另一个是摘要通知。我按照这些博客文章中所述的一切去做,一切似乎都有效。但是在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;
}
摘要通知
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();
}
然后我同时调用这两个函数。
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);
我应该如何解决双声问题?非常感谢您的帮助!