【发布时间】:2017-01-26 17:21:09
【问题描述】:
我正在尝试在用户打开活动时创建堆叠的本地通知。我看不到它们堆叠在一起。它们都单独出现。我提到了许多其他堆栈溢出问题,但没有一个有效。以下是我的代码:
public class NotificationGroupActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createNotifications();
}
private void createNotifications() {
final String GROUP_KEY_EMAILS = "group_key_emails";
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
for(int i = 0; i<10;i++) {
// Build the notification, setting the group appropriately
Notification notif = new NotificationCompat.Builder(this)
.setContentTitle("New mail from " + i)
.setContentText("SUBJECT " + i)
.setSmallIcon(R.mipmap.ic_launcher)
.setGroup(GROUP_KEY_EMAILS)
.setGroupSummary(true)
.build();
// Issue the notification
notificationManager.notify(i + 10, notif);
}
}
}
【问题讨论】:
标签: android notifications localnotification