Skip to content

Commit 88a7ad3

Browse files
authored
feat(channel): fixing json parsing issue (#79)
1 parent e2aa996 commit 88a7ad3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

AndroidSDK/src/com/leanplum/LeanplumNotificationChannel.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040

4141
import org.json.JSONArray;
4242

43+
import java.util.ArrayList;
4344
import java.util.HashMap;
45+
import java.util.Iterator;
4446
import java.util.List;
4547
import java.util.Map;
4648

@@ -602,10 +604,17 @@ private static class NotificationChannelData {
602604
showBadge = (boolean) CollectionUtil.getOrDefault(channel, "show_badge", showBadge);
603605

604606
try {
605-
List<Long> pattern = CollectionUtil.uncheckedCast(
607+
List<Number> pattern = CollectionUtil.uncheckedCast(
606608
CollectionUtil.getOrDefault(channel, "vibration_pattern", null));
607609
if (pattern != null) {
608-
vibrationPattern = CollectionUtil.toPrimitive(pattern.toArray(new Long[pattern.size()]));
610+
vibrationPattern = new long[pattern.size()];
611+
Iterator<Number> iterator = pattern.iterator();
612+
for (int i = 0; i < vibrationPattern.length; i++) {
613+
Number next = iterator.next();
614+
if (next != null) {
615+
vibrationPattern[i] = next.longValue();
616+
}
617+
}
609618
}
610619
} catch (Exception e) {
611620
Log.w("Failed to parse vibration pattern.");

AndroidSDKTests/src/test/java/com/leanplum/LeanplumNotificationChannelTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ public void testNotificationChannels() throws Exception {
9595
channel2.put("name", "name_2");
9696
channel2.put("importance", 1);
9797
channel2.put("description", "description_2");
98+
channel2.put("enable_vibration", true);
99+
channel2.put("vibration_pattern", new long[] {1L, 2L, 3L, 4L, 5L});
98100

99101
HashMap<String, Object> channel3 = new HashMap<>();
100102
channel3.put("id", "id_3");
101103
channel3.put("name", "name_3");
102104
channel3.put("importance", 1);
103105
channel3.put("description", "description_3");
106+
channel3.put("enable_vibration", true);
107+
channel3.put("vibration_pattern", new ArrayList<Long>() {{add(1L); add(2L); add(3L);}});
104108

105109
groupList.add(group1);
106110
groupList.add(group2);

0 commit comments

Comments
 (0)