diff --git a/example/main/java/cn/jpush/api/examples/PushExample.java b/example/main/java/cn/jpush/api/examples/PushExample.java index 73b7fcad..b455ec86 100644 --- a/example/main/java/cn/jpush/api/examples/PushExample.java +++ b/example/main/java/cn/jpush/api/examples/PushExample.java @@ -32,8 +32,8 @@ public class PushExample { protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class); // demo App defined in resources/jpush-api.conf - protected static final String APP_KEY = "e4ceeaf7a53ad745dd4728f2"; - protected static final String MASTER_SECRET = "1582b986adeaf48ceec1e354"; + protected static final String APP_KEY = "32f266ea08c3b3d7a059b378"; + protected static final String MASTER_SECRET = "03b3ab9ae0a099ef26dd2168"; protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c"; protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e"; @@ -48,15 +48,15 @@ public class PushExample { public static void main(String[] args) { // 回调参数可参考下面方法 - testSendPushWithCustom(); - testSendPushWithCustomField(); +// testSendPushWithCustom(); +// testSendPushWithCustomField(); // testBatchSend(); - testSendPushWithCustomConfig(); +// testSendPushWithCustomConfig(); // testSendIosAlert(); -// testSendPush(); + testSendPush(); // testGetCidList(); // testSendPushes(); - testSendPush_fromJSON(); +// testSendPush_fromJSON(); // testSendPushWithCallback(); // testSendPushWithCid(); } @@ -281,7 +281,8 @@ public static PushPayload buildPushObject_android_and_ios() { .setPlatform(Platform.android_ios()) .setAudience(Audience.all()) .setNotification(Notification.newBuilder() - .setAlert("alert content") + .setAiOpportunity(true) + .setAlert("testing alert content") .addPlatformNotification(AndroidNotification.newBuilder() .setTitle("Android Title") .addExtras(extras).build()) @@ -289,6 +290,10 @@ public static PushPayload buildPushObject_android_and_ios() { .incrBadge(1) .addExtra("extra_key", "extra_value").build()) .build()) + .setOptions(Options.newBuilder() + .setApnsProduction(false) + .setTimeToLive(43200) + .build()) .build(); } 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 cd94bfea..6072f93d 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 @@ -11,11 +11,13 @@ import cn.jiguang.common.utils.Preconditions; import cn.jpush.api.push.model.PushModel; -public class Notification implements PushModel { +public class Notification implements PushModel { + private boolean aiOpportunity = false; private final Object alert; private final Set notifications; - private Notification(Object alert, Set notifications) { + private Notification(boolean aiOpportunity, Object alert, Set notifications) { + this.aiOpportunity = aiOpportunity; this.alert = alert; this.notifications = notifications; } @@ -23,6 +25,10 @@ private Notification(Object alert, Set notifications) { public static Builder newBuilder() { return new Builder(); } + + public static Notification aiOpportunity(boolean ai_opportunity) { + return newBuilder().setAiOpportunity(ai_opportunity).build(); + } /** * Quick set all platform alert. @@ -92,6 +98,8 @@ public static Notification winphone(String alert, Map extras) { public JsonElement toJSON() { JsonObject json = new JsonObject(); + json.addProperty("ai_opportunity", aiOpportunity); + if (null != alert) { if(alert instanceof JsonObject) { json.add(PlatformNotification.ALERT, (JsonObject) alert); @@ -117,9 +125,15 @@ public JsonElement toJSON() { } public static class Builder { + private boolean aiOpportunity; private Object alert; private Set builder; - + + public Builder setAiOpportunity(boolean aiOpportunity) { + this.aiOpportunity = aiOpportunity; + return this; + } + public Builder setAlert(Object alert) { this.alert = alert; return this; @@ -134,9 +148,9 @@ public Builder addPlatformNotification(PlatformNotification notification) { } public Notification build() { - Preconditions.checkArgument(! (null == builder && null == alert), + Preconditions.checkArgument(! (null == builder && null == alert), "No notification payload is set."); - return new Notification(alert, builder); + return new Notification(aiOpportunity, alert, builder); } } }