/ / Android: Gruppierte Benachrichtigungen und Zusammenfassung weiterhin separat auf 4.4 und unten angezeigt - Android, Android-Benachrichtigungen, Android-Wear-Benachrichtigung

Android: Gruppierte Benachrichtigungen und Zusammenfassung weiterhin separat auf 4.4 und unten angezeigt - Android, Android-Benachrichtigungen, Android-Wear-Benachrichtigung

Ich möchte implementieren gestapelte Benachrichtigungen auf Android Wear Dazu erstelle ich 1 Sammelbenachrichtigung und N individuelle Benachrichtigungen für jeden "Gegenstand". Ich möchte nur die Zusammenfassung auf dem Telefon angezeigt werden. Hier ist mein Code:

private void showNotifications() {
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
showNotification1(notificationManager);
showNotification2(notificationManager);
showGroupSummaryNotification(notificationManager);
}

private void showNotification1(NotificationManager notificationManager) {
showSingleNotification(notificationManager, "title 1", "message 1", 1);
}

private void showNotification2(NotificationManager notificationManager) {
showSingleNotification(notificationManager, "title 2", "message 2", 2);
}

protected void showSingleNotification(NotificationManager notificationManager,
String title,
String message,
int notificationId) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(title)
.setContentText(message)
.setSmallIcon(R.mipmap.ic_launcher)
.setGroupSummary(false)
.setGroup("group");
Notification notification = builder.build();
notificationManager.notify(notificationId, notification);
}

private void showGroupSummaryNotification(NotificationManager notificationManager) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("Dummy content title")
.setContentText("Dummy content text")
.setStyle(new NotificationCompat.InboxStyle()
.addLine("Line 1")
.addLine("Line 2")
.setSummaryText("Inbox summary text")
.setBigContentTitle("Big content title"))
.setNumber(2)
.setSmallIcon(R.mipmap.ic_launcher)
.setCategory(Notification.CATEGORY_EVENT)
.setGroupSummary(true)
.setGroup("group");
Notification notification = builder.build();
notificationManager.notify(123456, notification);
}

Dies funktioniert auf Android 5.1 einwandfrei, nur die Zusammenfassung wird in der Benachrichtigungsleiste des Telefons angezeigt:

Bildbeschreibung hier eingeben

Aber auf Android 4.4 zeigt es auch individuelle Benachrichtigungen 1 und 2:

Bildbeschreibung hier eingeben

In beiden Fällen werden Benachrichtigungen auf Android Wear nach Wunsch in einem Stapel angezeigt. Wie mache ich Android 4.4 nur die Sammelbenachrichtigung in der Benachrichtigungsleiste anzeigen?

Antworten:

17 für die Antwort № 1

Dies wurde mit Hilfe von behoben

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

Anstatt von

NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

und Ersetzen von NotificationManager durch NotificationManagerCompat in entsprechenden Methodensignaturen.