我想堆叠即将到来的推送通知,但它们不分组。我会有很多通知,它们应该组合在一起。这是我的代码(我按照@ishmaelMakitla 的建议更新了代码):
Intent intent = new Intent(this, MainActivity.class);
intent.replaceExtras(extras);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (GROUP_ID != null) {
Log.i("Game", "Game GROUP ID " + "---- " + GROUP_ID);
int notId = GROUP_ID.equals(GROUP_ADDS) ? NOTIFICATION_ADD_ID : NOTIFICATION_GAME_ID;
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
if (isFirstTime == true) {
Notification firstNotification = new NotificationCompat.Builder(this)
.setContentTitle(messageTitle)
.setContentText(messageValue)
.setSmallIcon(R.drawable.take_4_free_logo_01)
.setGroup(GROUP_ID)
.setAutoCancel(true)
.setCategory(NotificationCompat.CATEGORY_SOCIAL)
.setGroupSummary(true)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(messageValue))
.setContentIntent(contentIntent)
.build();
notificationManager.notify(notId, firstNotification);
Log.i("Game", "Notification ID First time " + "---- " + notId);
isFirstTime = false;
} else {
Notification followUpNotification = new NotificationCompat.Builder(this)
.setContentTitle(messageTitle)
.setContentText(messageValue)
.setCategory(NotificationCompat.CATEGORY_SOCIAL)
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.take_4_free_logo_01)
.setGroup(GROUP_ID)
.build();
notificationManager.notify(notId, followUpNotification);
Log.i("Game", "Notification ID Following " + "---- " + notId);
}
// notify activity
Intent intentNewPush = new Intent(Consts.NEW_PUSH_EVENT);
intentNewPush.replaceExtras(extras);
LocalBroadcastManager.getInstance(this).sendBroadcast(intentNewPush);
}
最佳答案
您应该为第一个通知设置 .setGroupSummary(true) ONLY,这将成为一组通知的组摘要(在您的情况下属于组 GROUP_ID)。否则,每个带有 .setGroupSummary(true)
的通知都被视为单独的新通知。这是您可以快速运行的代码(扩展您的代码),如果它按预期工作,请告诉我。
Notification followUpNotification= new NotificationCompat.Builder(mContext)
.setContentTitle("Follow Up ")
.setContentText("Follow Up Message")
.setSmallIcon(R.drawable.free_logo_01)
.setGroup(GROUP_ID)
.build();
notificationManager.notify((notId+1), followUpNotification);
希望对您有所帮助。
关于android - android 推送通知分组不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37457073/