Skip to content

Commit 1a2335d

Browse files
committed
add example
1 parent 9908a9e commit 1a2335d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cn.jpush.api.examples;
22

3+
import cn.jpush.api.device.OnlineStatus;
34
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
56

@@ -8,11 +9,13 @@
89
import cn.jpush.api.common.resp.APIRequestException;
910
import cn.jpush.api.device.TagAliasResult;
1011

12+
import java.util.Map;
13+
1114
public class DevcieExample {
1215
protected static final Logger LOG = LoggerFactory.getLogger(DevcieExample.class);
1316

1417
private static final String appKey = "dd1066407b044738b6479275";
15-
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
18+
private static final String masterSecret = "6b135be0037a5c1e693c3dfa";
1619
private static final String TAG1 = "tag1";
1720
private static final String ALIAS1 = "alias1";
1821
private static final String ALIAS2 = "alias2";
@@ -22,7 +25,8 @@ public class DevcieExample {
2225
private static JPushClient jpushClient = new JPushClient(masterSecret, appKey);
2326

2427
public static void main(String[] args) {
25-
testGetDeviceTagAlias();
28+
// testGetDeviceTagAlias();
29+
testGetUserOnlineStatus();
2630
}
2731

2832
public static void testGetDeviceTagAlias() {
@@ -42,6 +46,22 @@ public static void testGetDeviceTagAlias() {
4246
LOG.info("Error Message: " + e.getErrorMessage());
4347
}
4448
}
49+
50+
public static void testGetUserOnlineStatus() {
51+
try {
52+
Map<String, OnlineStatus> result = jpushClient.getUserOnlineStatus(REGISTRATION_ID1, REGISTRATION_ID2);
53+
54+
LOG.info(result.get(REGISTRATION_ID1).toString());
55+
LOG.info(result.get(REGISTRATION_ID2).toString());
56+
} catch (APIConnectionException e) {
57+
LOG.error("Connection error. Should retry later. ", e);
58+
} catch (APIRequestException e) {
59+
LOG.error("Error response from JPush server. Should review and fix it. ", e);
60+
LOG.info("HTTP Status: " + e.getStatus());
61+
LOG.info("Error Code: " + e.getErrorCode());
62+
LOG.info("Error Message: " + e.getErrorMessage());
63+
}
64+
}
4565

4666
}
4767

0 commit comments

Comments
 (0)