diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java index 678f23e8e..95c647405 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java @@ -122,6 +122,8 @@ public void getDeliveredNotifications(PluginCall call) { if (notification != null) { jsNotif.put("title", notification.extras.getCharSequence(Notification.EXTRA_TITLE)); jsNotif.put("body", notification.extras.getCharSequence(Notification.EXTRA_TEXT)); + jsNotif.put("group", notification.getGroup()); + jsNotif.put("groupSummary", 0 != (notification.flags & Notification.FLAG_GROUP_SUMMARY)); JSObject extras = new JSObject(); diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotification.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotification.java index 469e37812..7df50102f 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotification.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotification.java @@ -32,6 +32,8 @@ public class LocalNotification { private String sound; private String smallIcon; private String actionTypeId; + private String group; + private boolean groupSummary; private JSObject extra; private List attachments; private LocalNotificationSchedule schedule; @@ -89,6 +91,14 @@ public void setActionTypeId(String actionTypeId) { this.actionTypeId = actionTypeId; } + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + public JSObject getExtra() { return extra; } @@ -105,6 +115,14 @@ public void setId(Integer id) { this.id = id; } + public boolean isGroupSummary() { + return groupSummary; + } + + public void setGroupSummary(boolean groupSummary) { + this.groupSummary = groupSummary; + } + /** * Build list of the notifications from remote plugin call */ @@ -136,10 +154,12 @@ public static List buildNotificationList(PluginCall call) { activeLocalNotification.setId(notification.getInteger("id")); activeLocalNotification.setBody(notification.getString("body")); activeLocalNotification.setActionTypeId(notification.getString("actionTypeId")); + activeLocalNotification.setGroup(notification.getString("group")); activeLocalNotification.setSound(notification.getString("sound")); activeLocalNotification.setTitle(notification.getString("title")); activeLocalNotification.setSmallIcon(notification.getString("smallIcon")); activeLocalNotification.setAttachments(LocalNotificationAttachment.getAttachments(notification)); + activeLocalNotification.setGroupSummary(notification.getBoolean("groupSummary", false)); try { activeLocalNotification.setSchedule(new LocalNotificationSchedule(notification)); } catch (ParseException e) { @@ -234,9 +254,11 @@ public String toString() { ", sound='" + sound + '\'' + ", smallIcon='" + smallIcon + '\'' + ", actionTypeId='" + actionTypeId + '\'' + + ", group='" + group + '\'' + ", extra=" + extra + ", attachments=" + attachments + ", schedule=" + schedule + + ", groupSummary=" + groupSummary + '}'; } @@ -254,9 +276,11 @@ public boolean equals(Object o) { if (smallIcon != null ? !smallIcon.equals(that.smallIcon) : that.smallIcon != null) return false; if (actionTypeId != null ? !actionTypeId.equals(that.actionTypeId) : that.actionTypeId != null) return false; + if (group != null ? !group.equals(that.group) : that.group != null) return false; if (extra != null ? !extra.equals(that.extra) : that.extra != null) return false; if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false; + if (groupSummary != that.groupSummary) return false; return schedule != null ? schedule.equals(that.schedule) : that.schedule == null; } @@ -268,6 +292,8 @@ public int hashCode() { result = 31 * result + (sound != null ? sound.hashCode() : 0); result = 31 * result + (smallIcon != null ? smallIcon.hashCode() : 0); result = 31 * result + (actionTypeId != null ? actionTypeId.hashCode() : 0); + result = 31 * result + (group != null ? group.hashCode() : 0); + result = 31 * result + Boolean.hashCode(groupSummary); result = 31 * result + (extra != null ? extra.hashCode() : 0); result = 31 * result + (attachments != null ? attachments.hashCode() : 0); result = 31 * result + (schedule != null ? schedule.hashCode() : 0); diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java index effd3ca49..20289a40c 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java @@ -149,6 +149,7 @@ private void buildNotification(NotificationManagerCompat notificationManager, Lo .setAutoCancel(true) .setOngoing(false) .setPriority(NotificationCompat.PRIORITY_DEFAULT) + .setGroupSummary(localNotification.isGroupSummary()) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS); String sound = localNotification.getSound(); @@ -161,6 +162,11 @@ private void buildNotification(NotificationManagerCompat notificationManager, Lo mBuilder.setSound(soundUri); } + String group = localNotification.getGroup(); + if (group != null) { + mBuilder.setGroup(group); + } + mBuilder.setVisibility(Notification.VISIBILITY_PRIVATE); mBuilder.setOnlyAlertOnce(true); diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index 2502bcba2..8400ecb14 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -1040,6 +1040,16 @@ export interface LocalNotification { * iOS 12+ only: set the summary argument for notification grouping */ summaryArgument?: string; + /** + * Android only: set the group identifier for notification grouping, like + * threadIdentifier on iOS. + */ + group?: string; + /** + * Android only: designate this notification as the summary for a group + * (should be used with the `group` property). + */ + groupSummary?: boolean; } export interface LocalNotificationSchedule { @@ -1437,6 +1447,16 @@ export interface PushNotification { data: any; click_action?: string; link?: string; + /** + * Android only: set the group identifier for notification grouping, like + * threadIdentifier on iOS. + */ + group?: string; + /** + * Android only: designate this notification as the summary for a group + * (should be used with the `group` property). + */ + groupSummary?: boolean; } export interface PushNotificationActionPerformed {