Android Oreo中的捆绑/分组通知显示同一组的单独通知
我正在尝试让捆绑/分组通知正常工作,到目前为止,它一直向我显示两个单独的通知,下面是我使用的代码:Android Oreo中的捆绑/分组通知显示同一组的单独通知,android,push-notification,android-8.0-oreo,Android,Push Notification,Android 8.0 Oreo,我正在尝试让捆绑/分组通知正常工作,到目前为止,它一直向我显示两个单独的通知,下面是我使用的代码: final int notificationId = 1; final String channelId = "my_channel_id_01"; final String groupKey = "my_group_id_01"; // The user-visible name of the channel. final String channelName = "My Testing Ch
final int notificationId = 1;
final String channelId = "my_channel_id_01";
final String groupKey = "my_group_id_01";
// The user-visible name of the channel.
final String channelName = "My Testing Channel";
// The user-visible description of the channel.
final String channelDesc = "Just testing a channel";
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel = null;
//define the channel
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
{
mChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
// Configure the notification channel.
mChannel.setDescription(channelDesc);
mChannel.enableLights(true);
// Sets the notification light color for notifications posted to this
// channel, if the device supports this feature.
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
if (mNotificationManager != null)
{
mNotificationManager.createNotificationChannel(mChannel);
}
}
//large icon
Bitmap largeIconBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
//notification builder
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(largeIconBitmap)
.setAutoCancel(true)
.setGroupSummary(true)
.setGroup(groupKey)
//when collapsed
.setContentTitle("Default notification")
.setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
.setContentInfo("Info")
//when expanded
.setStyle(new NotificationCompat.InboxStyle()
.setBigContentTitle("Content Text")
.setSummaryText("Summary text") //summary text
.addLine("Some text 1")
.addLine("Some text 2")
.addLine("Some text 3")
.addLine("Some text 4")
.addLine("Some text 5"));
//set category
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
notificationBuilder.setCategory(Notification.CATEGORY_SOCIAL);
}
//notify user
if (mNotificationManager != null)
{
//1st notification
mNotificationManager.notify(notificationId, notificationBuilder.build());
//2nd notification
mNotificationManager.notify(notificationId + 1, notificationBuilder.build());
}
结果如下:
我不确定我做错了什么。我将API v26与Android Oreo emulator映像(以及v26)一起使用。谢谢你的帮助 解决方案有更新吗?有更新@Sdghasemi吗?