booleanExtras,
@@ -73,7 +73,7 @@ public Builder setBuilderId(int builderId) {
return this;
}
- public Builder setAlert(String alert) {
+ public Builder setAlert(Object alert) {
this.alert = alert;
return this;
}
diff --git a/src/main/java/cn/jpush/api/push/model/notification/IosAlert.java b/src/main/java/cn/jpush/api/push/model/notification/IosAlert.java
new file mode 100644
index 00000000..19b4211a
--- /dev/null
+++ b/src/main/java/cn/jpush/api/push/model/notification/IosAlert.java
@@ -0,0 +1,128 @@
+package cn.jpush.api.push.model.notification;
+
+import cn.jpush.api.push.model.PushModel;
+import cn.jpush.api.utils.StringUtils;
+import com.google.gson.*;
+
+public class IosAlert implements PushModel {
+
+ private final String title;
+ private final String body;
+ private final String title_loc_key;
+ private final String[] title_loc_args;
+ private final String action_loc_key;
+ private final String loc_key;
+ private final String[] loc_args;
+ private final String launch_image;
+
+ private IosAlert(String title, String body, String title_loc_key, String[] title_loc_args,
+ String action_loc_key, String loc_key, String[] loc_args, String launch_image) {
+ this.title = title;
+ this.body = body;
+ this.title_loc_key = title_loc_key;
+ this.title_loc_args = title_loc_args;
+ this.action_loc_key = action_loc_key;
+ this.loc_key = loc_key;
+ this.loc_args = loc_args;
+ this.launch_image = launch_image;
+ }
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ @Override
+ public JsonElement toJSON() {
+ JsonObject json = new JsonObject();
+
+ if( StringUtils.isNotEmpty(title) ) {
+ json.addProperty("title", title);
+ }
+
+ if( StringUtils.isNotEmpty(title) ) {
+ json.addProperty("body", body);
+ }
+
+ if( StringUtils.isNotEmpty(title_loc_key) ) {
+ json.addProperty("title-loc-key", title_loc_key);
+ if( null != title_loc_args && title_loc_args.length > 0 ) {
+ JsonArray args = new JsonArray();
+ for(int i = 0; i < title_loc_args.length; i++) {
+ args.add(new JsonPrimitive(title_loc_args[i]));
+ }
+ json.add("title-loc-args", args);
+ }
+ }
+
+ if( StringUtils.isNotEmpty(action_loc_key) ) {
+ json.addProperty("action-loc-key", action_loc_key);
+ }
+
+ if( StringUtils.isNotEmpty(loc_key) ) {
+ json.addProperty("loc-key", loc_key);
+ if( null != loc_args && loc_args.length > 0 ) {
+ JsonArray args = new JsonArray();
+ for(int i = 0; i < loc_args.length; i++) {
+ args.add(new JsonPrimitive(loc_args[i]));
+ }
+ json.add("loc-args", args);
+ }
+ }
+
+ if( StringUtils.isNotEmpty(launch_image) ) {
+ json.addProperty("launch-image", launch_image);
+ }
+
+ return json;
+ }
+
+ @Override
+ public String toString() {
+ return gson.toJson(toJSON());
+ }
+
+ public static class Builder {
+ private String title;
+ private String body;
+ private String title_loc_key;
+ private String[] title_loc_args;
+ private String action_loc_key;
+ private String loc_key;
+ private String[] loc_args;
+ private String launch_image;
+
+ public Builder setTitleAndBody(String title, String body){
+ this.title = title;
+ this.body = body;
+ return this;
+ }
+
+ public Builder setTitleLoc(String title_loc_key, String... title_loc_args) {
+ this.title_loc_key = title_loc_key;
+ this.title_loc_args = title_loc_args;
+ return this;
+ }
+
+ public Builder setActionLocKey(String action_loc_key) {
+ this.action_loc_key = action_loc_key;
+ return this;
+ }
+
+ public Builder setLoc(String loc_key, String... loc_args) {
+ this.loc_key = loc_key;
+ this.loc_args = loc_args;
+ return this;
+ }
+
+ public Builder setLaunchImage(String launch_image) {
+ this.launch_image = launch_image;
+ return this;
+ }
+
+ public IosAlert build() {
+ return new IosAlert(title, body, title_loc_key, title_loc_args, action_loc_key,
+ loc_key, loc_args, launch_image);
+ }
+ }
+
+}
diff --git a/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java b/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java
index bcd6b191..92af6169 100644
--- a/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java
+++ b/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java
@@ -1,13 +1,12 @@
package cn.jpush.api.push.model.notification;
-import java.util.Map;
-
import cn.jpush.api.common.ServiceHelper;
-
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import java.util.Map;
+
/**
* APNs 通知类
*
@@ -46,7 +45,7 @@ public class IosNotification extends PlatformNotification {
private final boolean contentAvailable;
private final String category;
- private IosNotification(String alert, String sound, String badge,
+ private IosNotification(Object alert, String sound, String badge,
boolean contentAvailable, boolean soundDisabled, boolean badgeDisabled,
String category,
Map extras,
@@ -173,11 +172,11 @@ public Builder setCategory(String category) {
return this;
}
- public Builder setAlert(String alert) {
+ public Builder setAlert(Object alert) {
this.alert = alert;
return this;
}
-
+
public IosNotification build() {
return new IosNotification(alert, sound, badge, contentAvailable,
diff --git a/src/main/java/cn/jpush/api/push/model/notification/Notification.java b/src/main/java/cn/jpush/api/push/model/notification/Notification.java
index f8575bc9..4134a7ac 100644
--- a/src/main/java/cn/jpush/api/push/model/notification/Notification.java
+++ b/src/main/java/cn/jpush/api/push/model/notification/Notification.java
@@ -1,21 +1,20 @@
package cn.jpush.api.push.model.notification;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
import cn.jpush.api.push.model.PushModel;
import cn.jpush.api.utils.Preconditions;
-
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
public class Notification implements PushModel {
- private final String alert;
+ private final Object alert;
private final Set notifications;
- private Notification(String alert, Set notifications) {
+ private Notification(Object alert, Set notifications) {
this.alert = alert;
this.notifications = notifications;
}
@@ -31,7 +30,7 @@ public static Builder newBuilder() {
* @param alert Notification alert
* @return first level notification object
*/
- public static Notification alert(String alert) {
+ public static Notification alert(Object alert) {
return newBuilder().setAlert(alert).build();
}
@@ -51,7 +50,7 @@ public static Notification android(String alert, String title, Map extras) {
+ public static Notification ios(Object alert, Map extras) {
return newBuilder()
.addPlatformNotification(IosNotification.newBuilder()
.setAlert(alert)
@@ -111,7 +110,13 @@ public static Notification winphone(String alert, Map extras) {
public JsonElement toJSON() {
JsonObject json = new JsonObject();
if (null != alert) {
- json.add(PlatformNotification.ALERT, new JsonPrimitive(alert));
+ if(alert instanceof JsonObject) {
+ json.add(PlatformNotification.ALERT, (JsonObject) alert);
+ } else if (alert instanceof IosAlert) {
+ json.add(PlatformNotification.ALERT, ((IosAlert) alert).toJSON());
+ } else {
+ json.add(PlatformNotification.ALERT, new JsonPrimitive(alert.toString()));
+ }
}
if (null != notifications) {
for (PlatformNotification pn : notifications) {
@@ -129,10 +134,10 @@ public JsonElement toJSON() {
}
public static class Builder {
- private String alert;
+ private Object alert;
private Set builder;
- public Builder setAlert(String alert) {
+ public Builder setAlert(Object alert) {
this.alert = alert;
return this;
}
diff --git a/src/main/java/cn/jpush/api/push/model/notification/PlatformNotification.java b/src/main/java/cn/jpush/api/push/model/notification/PlatformNotification.java
index da87ee74..9ad0925e 100644
--- a/src/main/java/cn/jpush/api/push/model/notification/PlatformNotification.java
+++ b/src/main/java/cn/jpush/api/push/model/notification/PlatformNotification.java
@@ -1,17 +1,15 @@
package cn.jpush.api.push.model.notification;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import cn.jpush.api.push.model.PushModel;
import cn.jpush.api.utils.Preconditions;
-
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
public abstract class PlatformNotification implements PushModel {
public static final String ALERT = "alert";
@@ -19,13 +17,13 @@ public abstract class PlatformNotification implements PushModel {
protected static final Logger LOG = LoggerFactory.getLogger(PlatformNotification.class);
- private String alert;
+ private Object alert;
private final Map extras;
private final Map numberExtras;
private final Map booleanExtras;
private final Map jsonExtras;
- public PlatformNotification(String alert, Map extras,
+ public PlatformNotification(Object alert, Map extras,
Map numberExtras,
Map booleanExtras,
Map jsonExtras) {
@@ -41,7 +39,13 @@ public JsonElement toJSON() {
JsonObject json = new JsonObject();
if (null != alert) {
- json.add(ALERT, new JsonPrimitive(this.alert));
+ if ( alert instanceof JsonObject) {
+ json.add(ALERT, (JsonObject) alert);
+ } else if (alert instanceof IosAlert) {
+ json.add(PlatformNotification.ALERT, ((IosAlert) alert).toJSON());
+ } else {
+ json.add(PlatformNotification.ALERT, new JsonPrimitive(alert.toString()));
+ }
}
JsonObject extrasObject = null;
@@ -93,11 +97,11 @@ public JsonElement toJSON() {
return json;
}
- protected String getAlert() {
+ protected Object getAlert() {
return this.alert;
}
- protected void setAlert(String alert) {
+ protected void setAlert(Object alert) {
this.alert = alert;
}
@@ -106,7 +110,7 @@ protected void setAlert(String alert) {
protected abstract static class Builder> {
private B theBuilder;
- protected String alert;
+ protected Object alert;
protected Map extrasBuilder;
protected Map numberExtrasBuilder;
protected Map booleanExtrasBuilder;
@@ -118,7 +122,7 @@ public Builder () {
protected abstract B getThis();
- public abstract B setAlert(String alert);
+ public abstract B setAlert(Object alert);
public B addExtra(String key, String value) {
Preconditions.checkArgument(! (null == key), "Key should not be null.");
diff --git a/src/main/java/cn/jpush/api/push/model/notification/WinphoneNotification.java b/src/main/java/cn/jpush/api/push/model/notification/WinphoneNotification.java
index 388da698..9ceecf52 100644
--- a/src/main/java/cn/jpush/api/push/model/notification/WinphoneNotification.java
+++ b/src/main/java/cn/jpush/api/push/model/notification/WinphoneNotification.java
@@ -1,11 +1,11 @@
package cn.jpush.api.push.model.notification;
-import java.util.Map;
-
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import java.util.Map;
+
public class WinphoneNotification extends PlatformNotification {
private static final String NOTIFICATION_WINPHONE = "winphone";
@@ -15,7 +15,7 @@ public class WinphoneNotification extends PlatformNotification {
private final String title;
private final String openPage;
- private WinphoneNotification(String alert, String title, String openPage,
+ private WinphoneNotification(Object alert, String title, String openPage,
Map extras,
Map numberExtras,
Map booleanExtras,
@@ -73,7 +73,7 @@ public Builder setOpenPage(String openPage) {
return this;
}
- public Builder setAlert(String alert) {
+ public Builder setAlert(Object alert) {
this.alert = alert;
return this;
}
diff --git a/src/main/resources/javadoc-overview.html b/src/main/resources/javadoc-overview.html
index 7b36a45e..09fd5e36 100644
--- a/src/main/resources/javadoc-overview.html
+++ b/src/main/resources/javadoc-overview.html
@@ -5,6 +5,6 @@
JPush API Java 客户端。
- 主要分为 4 个功能部分:推送、报表、Tag/Alias管理、定时任务管理
+ 主要分为 4 个功能部分:推送、报表、Device管理、定时任务管理