Skip to content

Commit

Permalink
Merge pull request #123 from JoshLipan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JoshLipan authored Nov 15, 2018
2 parents ff4c3cd + 5bb1db9 commit b156b4a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.3.8</version>
<version>3.3.9</version>
</dependency>
```
### jar 包方式
Expand Down
14 changes: 13 additions & 1 deletion example/main/java/cn/jpush/api/examples/PushExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ public static void buildPushObject_with_extra() {
}

public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage() {
JsonObject sound = new JsonObject();
sound.add("critical", new JsonPrimitive(1));
sound.add("name", new JsonPrimitive("default"));
sound.add("volume", new JsonPrimitive(0.2));
return PushPayload.newBuilder()
.setPlatform(Platform.ios())
.setAudience(Audience.tag_and("tag1", "tag_all"))
Expand All @@ -294,7 +298,8 @@ public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage()
.setAlert(ALERT)
.setBadge(5)
.setMutableContent(false)
.setSound("happy")
// .setSound("happy")
.setSound(sound)
.addExtra("from", "JPush")
.build())
.build())
Expand All @@ -306,11 +311,16 @@ public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage()
}

public static PushPayload buildPushObject_android_newly_support() {

JsonObject inbox = new JsonObject();
inbox.add("line1", new JsonPrimitive("line1 string"));
inbox.add("line2", new JsonPrimitive("line2 string"));
inbox.add("contentTitle", new JsonPrimitive("title string"));
inbox.add("summaryText", new JsonPrimitive("+3 more"));

JsonObject intent = new JsonObject();
intent.add("url", new JsonPrimitive("intent:#Intent;component=com.jiguang.push/com.example.jpushdemo.SettingActivity;end"));

Notification notification = Notification.newBuilder()
.addPlatformNotification(AndroidNotification.newBuilder()
.setAlert(ALERT)
Expand All @@ -322,6 +332,8 @@ public static PushPayload buildPushObject_android_newly_support() {
.setStyle(1)
.setTitle("Alert test")
.setPriority(1)
.setLargeIcon("http://www.jiguang.cn/largeIcon.jpg")
.setIntent(intent)
.build())
.build();
return PushPayload.newBuilder()
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.3.9-SNAPSHOT</version>
<version>3.3.10-SNAPSHOT</version>
<packaging>jar</packaging>
<url>https://github.com/jpush/jpush-api-java-client</url>
<name>JPush API Java Client</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class AndroidNotification extends PlatformNotification {
private static final String BIG_PIC_PATH = "big_pic_path";
private static final String PRIORITY = "priority";
private static final String CATEGORY = "category";
private static final String LARGE_ICON = "large_icon";
private static final String INTENT = "intent";

private final String title;
private final int builderId;
Expand All @@ -30,9 +32,11 @@ public class AndroidNotification extends PlatformNotification {
private String big_pic_path;
private int priority;
private String category;
private String large_icon;
private JsonObject intent;

private AndroidNotification(Object alert, String title, int builderId, int style, int alertType, String bigText,
Object inbox, String bigPicPath, int priority, String category,
Object inbox, String bigPicPath, int priority, String category,String large_icon,JsonObject intent,
Map<String, String> extras,
Map<String, Number> numberExtras,
Map<String, Boolean> booleanExtras,
Expand All @@ -48,6 +52,8 @@ private AndroidNotification(Object alert, String title, int builderId, int style
this.big_pic_path = bigPicPath;
this.priority = priority;
this.category = category;
this.large_icon = large_icon;
this.intent = intent;
}

public static Builder newBuilder() {
Expand Down Expand Up @@ -115,6 +121,14 @@ public JsonElement toJSON() {
json.add(CATEGORY, new JsonPrimitive(category));
}

if (null != large_icon) {
json.add(LARGE_ICON, new JsonPrimitive(large_icon));
}

if (null != intent) {
json.add(INTENT, intent);
}

return json;
}

Expand All @@ -129,6 +143,8 @@ public static class Builder extends PlatformNotification.Builder<AndroidNotifica
private String big_pic_path;
private int priority;
private String category;
private String large_icon;
private JsonObject intent;

protected Builder getThis() {
return this;
Expand Down Expand Up @@ -188,10 +204,24 @@ public Builder setInbox(Object inbox) {
return this;
}

public Builder setLargeIcon(String largeIcon) {
this.large_icon = largeIcon;
return this;
}

public Builder setIntent(JsonObject intent) {
if (null == inbox) {
LOG.warn("Null intent. Throw away it.");
return this;
}
this.intent = intent;
return this;
}


public AndroidNotification build() {
return new AndroidNotification(alert, title, builderId, style, alert_type, big_text, inbox, big_pic_path, priority,
category, extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder);
category, large_icon, intent,extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* <ul>
* <li>alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。</li>
* <li>badge: 支持 setBadge(int) 方法来设置;支持 incrBadge(int) 方法来增加。</li>
* <li>sound: 支持 setSound(string) 方法来设置声音文件。</li>
* <li>sound: 支持 setSound(string) 方法来设置声音文件。或者 setSound(JSON object) 对应官方payload结构 </li>
* <li>content-available: 用来支持后台推送。如果该值赋值为 1,表示开启后台推送。</li>
* <li>extras: JSON object. 支持更多的自定义字段信息。</li>
* </ul>
Expand Down Expand Up @@ -44,14 +44,14 @@ public class IosNotification extends PlatformNotification {

private final boolean soundDisabled;
private final boolean badgeDisabled;
private final String sound;
private final Object sound;
private final String badge;
private final boolean contentAvailable;
private final String category;
private final boolean mutableContent;


private IosNotification(Object alert, String sound, String badge,
private IosNotification(Object alert, Object sound, String badge,
boolean contentAvailable, boolean soundDisabled, boolean badgeDisabled,
String category, boolean mutableContent,
Map<String, String> extras,
Expand Down Expand Up @@ -96,7 +96,12 @@ public JsonElement toJSON() {
}
if (!soundDisabled) {
if (null != sound) {
json.add(SOUND, new JsonPrimitive(sound));
if(sound instanceof String){
json.add(SOUND, new JsonPrimitive((String)sound));
}else if (sound instanceof JsonObject) {
json.add(SOUND, (JsonObject) sound);
}

} else {
json.add(SOUND, new JsonPrimitive(DEFAULT_SOUND));
}
Expand All @@ -116,7 +121,7 @@ public JsonElement toJSON() {


public static class Builder extends PlatformNotification.Builder<IosNotification, Builder> {
private String sound;
private Object sound;
private String badge;
private boolean contentAvailable = false;
private boolean soundDisabled = false;
Expand All @@ -128,7 +133,11 @@ protected Builder getThis() {
return this;
}

public Builder setSound(String sound) {
public Builder setSound(Object sound) {
if (null == sound) {
LOG.warn("Null sound. Throw away it.");
return this;
}
this.sound = sound;
return this;
}
Expand Down

0 comments on commit b156b4a

Please sign in to comment.