Skip to content

Commit 9eeb55e

Browse files
committed
增加对智能时机参数的支持 v4.3.11
1 parent 33c8495 commit 9eeb55e

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

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

+13-8
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public class PushExample {
3232
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);
3333

3434
// demo App defined in resources/jpush-api.conf
35-
protected static final String APP_KEY = "e4ceeaf7a53ad745dd4728f2";
36-
protected static final String MASTER_SECRET = "1582b986adeaf48ceec1e354";
35+
protected static final String APP_KEY = "32f266ea08c3b3d7a059b378";
36+
protected static final String MASTER_SECRET = "03b3ab9ae0a099ef26dd2168";
3737
protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c";
3838
protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e";
3939

@@ -48,15 +48,15 @@ public class PushExample {
4848
public static void main(String[] args) {
4949

5050
// 回调参数可参考下面方法
51-
testSendPushWithCustom();
52-
testSendPushWithCustomField();
51+
// testSendPushWithCustom();
52+
// testSendPushWithCustomField();
5353
// testBatchSend();
54-
testSendPushWithCustomConfig();
54+
// testSendPushWithCustomConfig();
5555
// testSendIosAlert();
56-
// testSendPush();
56+
testSendPush();
5757
// testGetCidList();
5858
// testSendPushes();
59-
testSendPush_fromJSON();
59+
// testSendPush_fromJSON();
6060
// testSendPushWithCallback();
6161
// testSendPushWithCid();
6262
}
@@ -281,14 +281,19 @@ public static PushPayload buildPushObject_android_and_ios() {
281281
.setPlatform(Platform.android_ios())
282282
.setAudience(Audience.all())
283283
.setNotification(Notification.newBuilder()
284-
.setAlert("alert content")
284+
.setAiOpportunity(true)
285+
.setAlert("testing alert content")
285286
.addPlatformNotification(AndroidNotification.newBuilder()
286287
.setTitle("Android Title")
287288
.addExtras(extras).build())
288289
.addPlatformNotification(IosNotification.newBuilder()
289290
.incrBadge(1)
290291
.addExtra("extra_key", "extra_value").build())
291292
.build())
293+
.setOptions(Options.newBuilder()
294+
.setApnsProduction(false)
295+
.setTimeToLive(43200)
296+
.build())
292297
.build();
293298
}
294299

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

+19-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@
1111
import cn.jiguang.common.utils.Preconditions;
1212
import cn.jpush.api.push.model.PushModel;
1313

14-
public class Notification implements PushModel {
14+
public class Notification implements PushModel {
15+
private boolean aiOpportunity = false;
1516
private final Object alert;
1617
private final Set<PlatformNotification> notifications;
1718

18-
private Notification(Object alert, Set<PlatformNotification> notifications) {
19+
private Notification(boolean aiOpportunity, Object alert, Set<PlatformNotification> notifications) {
20+
this.aiOpportunity = aiOpportunity;
1921
this.alert = alert;
2022
this.notifications = notifications;
2123
}
2224

2325
public static Builder newBuilder() {
2426
return new Builder();
2527
}
28+
29+
public static Notification aiOpportunity(boolean ai_opportunity) {
30+
return newBuilder().setAiOpportunity(ai_opportunity).build();
31+
}
2632

2733
/**
2834
* Quick set all platform alert.
@@ -92,6 +98,8 @@ public static Notification winphone(String alert, Map<String, String> extras) {
9298

9399
public JsonElement toJSON() {
94100
JsonObject json = new JsonObject();
101+
json.addProperty("ai_opportunity", aiOpportunity);
102+
95103
if (null != alert) {
96104
if(alert instanceof JsonObject) {
97105
json.add(PlatformNotification.ALERT, (JsonObject) alert);
@@ -117,9 +125,15 @@ public JsonElement toJSON() {
117125
}
118126

119127
public static class Builder {
128+
private boolean aiOpportunity;
120129
private Object alert;
121130
private Set<PlatformNotification> builder;
122-
131+
132+
public Builder setAiOpportunity(boolean aiOpportunity) {
133+
this.aiOpportunity = aiOpportunity;
134+
return this;
135+
}
136+
123137
public Builder setAlert(Object alert) {
124138
this.alert = alert;
125139
return this;
@@ -134,9 +148,9 @@ public Builder addPlatformNotification(PlatformNotification notification) {
134148
}
135149

136150
public Notification build() {
137-
Preconditions.checkArgument(! (null == builder && null == alert),
151+
Preconditions.checkArgument(! (null == builder && null == alert),
138152
"No notification payload is set.");
139-
return new Notification(alert, builder);
153+
return new Notification(aiOpportunity, alert, builder);
140154
}
141155
}
142156
}

0 commit comments

Comments
 (0)