Skip to content

Commit 4d1b3a4

Browse files
committed
Fix notification parsing
* Fix OSNotification creation with additional data under Android * Fix OSNotification creation with background image titleTextColor not being initialize correctly * Fix OSNotification jsonRepresentation method
1 parent 11fde0d commit 4d1b3a4

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

android/src/main/java/com/onesignal/flutter/OneSignalSerializer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ static HashMap<String, Object> convertNotificationToMap(OSNotification notificat
143143
if (notification.getCollapseId() != null)
144144
hash.put("collapseId", notification.getCollapseId());
145145
hash.put("priority", notification.getPriority());
146-
if (notification.getAdditionalData() != null)
147-
hash.put("additionalData", notification.getAdditionalData());
148-
149-
if (notification.getActionButtons() != null) {
146+
if (notification.getAdditionalData() != null && notification.getAdditionalData().length() > 0)
147+
hash.put("additionalData", convertJSONObjectToHashMap(notification.getAdditionalData()));
148+
if (notification.getActionButtons() != null && !notification.getActionButtons().isEmpty()) {
150149
ArrayList<HashMap> buttons = new ArrayList<>();
151150

152151
List<OSNotification.ActionButton> actionButtons = notification.getActionButtons();
@@ -168,7 +167,7 @@ static HashMap<String, Object> convertNotificationToMap(OSNotification notificat
168167

169168
hash.put("rawPayload", notification.getRawPayload());
170169

171-
Log.d("onesignal", "Created json raw payload: " + convertJSONObjectToHashMap(new JSONObject(notification.getRawPayload())).toString());
170+
Log.d("onesignal", "Created json raw payload: " + hash.toString());
172171

173172
return hash;
174173
}
@@ -235,7 +234,7 @@ private static HashMap<String, Object> convertAndroidBackgroundImageLayoutToMap(
235234

236235
hash.put("image", layout.getImage());
237236
hash.put("bodyTextColor", layout.getBodyTextColor());
238-
hash.put("titleTextColor", layout.getBodyTextColor());
237+
hash.put("titleTextColor", layout.getTitleTextColor());
239238

240239
return hash;
241240
}

lib/src/notification.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class OSNotification extends JSONStringRepresentable {
171171

172172
//converts JSON map to OSNotification instance
173173
OSNotification(Map<String, dynamic> json) {
174-
175174
// iOS Specific Parameters
176175
if (json.containsKey('contentAvailable'))
177176
this.contentAvailable = json['contentAvailable'] as bool?;
@@ -386,7 +385,7 @@ class OSNotificationReceivedEvent extends JSONStringRepresentable {
386385

387386
String jsonRepresentation() {
388387
return convertToJsonString({
389-
'notification': this.notification.jsonRepresentation
388+
'notification': this.notification.jsonRepresentation()
390389
});
391390
}
392391
}

0 commit comments

Comments
 (0)