我正在使用 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");
}