将NotificationManager替换为NotificationManagerCompat
使用通知管理器
private void send() {
Notification notification1 =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("News1")
.setGroup("News")
.setContentText("Text")
.build();
Notification notification2 =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("News2")
.setGroup("News")
.setContentText("Text2")
.build();
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1 , notification1);
notificationManager.notify(2 , notification2);
Notification Summary = new NotificationCompat.Builder(this)
.setContentTitle("2 new News")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("Text2")
.setGroup("News")
.setGroupSummary(true)
.build();
notificationManager.notify(-1 , Summary);
}
使用NotificationManagerCompat
private void send() {
Notification notification1 =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("News1")
.setGroup("News")
.setContentText("Text")
.build();
Notification notification2 =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("News2")
.setGroup("News")
.setContentText("Text2")
.build();
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
notificationManager.notify(1 , notification1);
notificationManager.notify(2 , notification2);
Notification Summary = new NotificationCompat.Builder(this)
.setContentTitle("2 new News")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("Text2")
.setGroup("News")
.setGroupSummary(true)
.build();
notificationManager.notify(-1 , Summary);
}