Skip to content

Commit ca3f442

Browse files
authored
Merge pull request #124 from jpush/dev
Dev
2 parents 11fde7e + b156b4a commit ca3f442

File tree

5 files changed

+62
-11
lines changed

5 files changed

+62
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>cn.jpush.api</groupId>
2626
<artifactId>jpush-client</artifactId>
27-
<version>3.3.8</version>
27+
<version>3.3.9</version>
2828
</dependency>
2929
```
3030
### jar 包方式

example/main/java/cn/jpush/api/examples/PushExample.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ public static void buildPushObject_with_extra() {
286286
}
287287

288288
public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage() {
289+
JsonObject sound = new JsonObject();
290+
sound.add("critical", new JsonPrimitive(1));
291+
sound.add("name", new JsonPrimitive("default"));
292+
sound.add("volume", new JsonPrimitive(0.2));
289293
return PushPayload.newBuilder()
290294
.setPlatform(Platform.ios())
291295
.setAudience(Audience.tag_and("tag1", "tag_all"))
@@ -294,7 +298,8 @@ public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage()
294298
.setAlert(ALERT)
295299
.setBadge(5)
296300
.setMutableContent(false)
297-
.setSound("happy")
301+
// .setSound("happy")
302+
.setSound(sound)
298303
.addExtra("from", "JPush")
299304
.build())
300305
.build())
@@ -306,11 +311,16 @@ public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage()
306311
}
307312

308313
public static PushPayload buildPushObject_android_newly_support() {
314+
309315
JsonObject inbox = new JsonObject();
310316
inbox.add("line1", new JsonPrimitive("line1 string"));
311317
inbox.add("line2", new JsonPrimitive("line2 string"));
312318
inbox.add("contentTitle", new JsonPrimitive("title string"));
313319
inbox.add("summaryText", new JsonPrimitive("+3 more"));
320+
321+
JsonObject intent = new JsonObject();
322+
intent.add("url", new JsonPrimitive("intent:#Intent;component=com.jiguang.push/com.example.jpushdemo.SettingActivity;end"));
323+
314324
Notification notification = Notification.newBuilder()
315325
.addPlatformNotification(AndroidNotification.newBuilder()
316326
.setAlert(ALERT)
@@ -322,6 +332,8 @@ public static PushPayload buildPushObject_android_newly_support() {
322332
.setStyle(1)
323333
.setTitle("Alert test")
324334
.setPriority(1)
335+
.setLargeIcon("http://www.jiguang.cn/largeIcon.jpg")
336+
.setIntent(intent)
325337
.build())
326338
.build();
327339
return PushPayload.newBuilder()

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>cn.jpush.api</groupId>
55
<artifactId>jpush-client</artifactId>
6-
<version>3.3.9-SNAPSHOT</version>
6+
<version>3.3.10-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<url>https://github.com/jpush/jpush-api-java-client</url>
99
<name>JPush API Java Client</name>

src/main/java/cn/jpush/api/push/model/notification/AndroidNotification.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class AndroidNotification extends PlatformNotification {
1818
private static final String BIG_PIC_PATH = "big_pic_path";
1919
private static final String PRIORITY = "priority";
2020
private static final String CATEGORY = "category";
21+
private static final String LARGE_ICON = "large_icon";
22+
private static final String INTENT = "intent";
2123

2224
private final String title;
2325
private final int builderId;
@@ -30,9 +32,11 @@ public class AndroidNotification extends PlatformNotification {
3032
private String big_pic_path;
3133
private int priority;
3234
private String category;
35+
private String large_icon;
36+
private JsonObject intent;
3337

3438
private AndroidNotification(Object alert, String title, int builderId, int style, int alertType, String bigText,
35-
Object inbox, String bigPicPath, int priority, String category,
39+
Object inbox, String bigPicPath, int priority, String category,String large_icon,JsonObject intent,
3640
Map<String, String> extras,
3741
Map<String, Number> numberExtras,
3842
Map<String, Boolean> booleanExtras,
@@ -48,6 +52,8 @@ private AndroidNotification(Object alert, String title, int builderId, int style
4852
this.big_pic_path = bigPicPath;
4953
this.priority = priority;
5054
this.category = category;
55+
this.large_icon = large_icon;
56+
this.intent = intent;
5157
}
5258

5359
public static Builder newBuilder() {
@@ -115,6 +121,14 @@ public JsonElement toJSON() {
115121
json.add(CATEGORY, new JsonPrimitive(category));
116122
}
117123

124+
if (null != large_icon) {
125+
json.add(LARGE_ICON, new JsonPrimitive(large_icon));
126+
}
127+
128+
if (null != intent) {
129+
json.add(INTENT, intent);
130+
}
131+
118132
return json;
119133
}
120134

@@ -129,6 +143,8 @@ public static class Builder extends PlatformNotification.Builder<AndroidNotifica
129143
private String big_pic_path;
130144
private int priority;
131145
private String category;
146+
private String large_icon;
147+
private JsonObject intent;
132148

133149
protected Builder getThis() {
134150
return this;
@@ -188,10 +204,24 @@ public Builder setInbox(Object inbox) {
188204
return this;
189205
}
190206

207+
public Builder setLargeIcon(String largeIcon) {
208+
this.large_icon = largeIcon;
209+
return this;
210+
}
211+
212+
public Builder setIntent(JsonObject intent) {
213+
if (null == inbox) {
214+
LOG.warn("Null intent. Throw away it.");
215+
return this;
216+
}
217+
this.intent = intent;
218+
return this;
219+
}
220+
191221

192222
public AndroidNotification build() {
193223
return new AndroidNotification(alert, title, builderId, style, alert_type, big_text, inbox, big_pic_path, priority,
194-
category, extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder);
224+
category, large_icon, intent,extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder);
195225
}
196226
}
197227
}

src/main/java/cn/jpush/api/push/model/notification/IosNotification.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* <ul>
1616
* <li>alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。</li>
1717
* <li>badge: 支持 setBadge(int) 方法来设置;支持 incrBadge(int) 方法来增加。</li>
18-
* <li>sound: 支持 setSound(string) 方法来设置声音文件。</li>
18+
* <li>sound: 支持 setSound(string) 方法来设置声音文件。或者 setSound(JSON object) 对应官方payload结构 </li>
1919
* <li>content-available: 用来支持后台推送。如果该值赋值为 1,表示开启后台推送。</li>
2020
* <li>extras: JSON object. 支持更多的自定义字段信息。</li>
2121
* </ul>
@@ -44,14 +44,14 @@ public class IosNotification extends PlatformNotification {
4444

4545
private final boolean soundDisabled;
4646
private final boolean badgeDisabled;
47-
private final String sound;
47+
private final Object sound;
4848
private final String badge;
4949
private final boolean contentAvailable;
5050
private final String category;
5151
private final boolean mutableContent;
5252

5353

54-
private IosNotification(Object alert, String sound, String badge,
54+
private IosNotification(Object alert, Object sound, String badge,
5555
boolean contentAvailable, boolean soundDisabled, boolean badgeDisabled,
5656
String category, boolean mutableContent,
5757
Map<String, String> extras,
@@ -96,7 +96,12 @@ public JsonElement toJSON() {
9696
}
9797
if (!soundDisabled) {
9898
if (null != sound) {
99-
json.add(SOUND, new JsonPrimitive(sound));
99+
if(sound instanceof String){
100+
json.add(SOUND, new JsonPrimitive((String)sound));
101+
}else if (sound instanceof JsonObject) {
102+
json.add(SOUND, (JsonObject) sound);
103+
}
104+
100105
} else {
101106
json.add(SOUND, new JsonPrimitive(DEFAULT_SOUND));
102107
}
@@ -116,7 +121,7 @@ public JsonElement toJSON() {
116121

117122

118123
public static class Builder extends PlatformNotification.Builder<IosNotification, Builder> {
119-
private String sound;
124+
private Object sound;
120125
private String badge;
121126
private boolean contentAvailable = false;
122127
private boolean soundDisabled = false;
@@ -128,7 +133,11 @@ protected Builder getThis() {
128133
return this;
129134
}
130135

131-
public Builder setSound(String sound) {
136+
public Builder setSound(Object sound) {
137+
if (null == sound) {
138+
LOG.warn("Null sound. Throw away it.");
139+
return this;
140+
}
132141
this.sound = sound;
133142
return this;
134143
}

0 commit comments

Comments
 (0)