JPush Util
JPush Util
/**
* 极光 push- AppKey 测试
*/
private static String APP_KEY = "";
/**
* 极光 push- MasterSecret 测试
*/
private static String MASTER_SECRET = "";
/**
* 极光 push- APNS 开发环境(TRUE-生产环境,FALSE-开发环境)
*/
private static String APNS_PRODUCTION = "false";
/**
* 极光 push- 调用推送消息时,设置保留的时长(格式:60 * 60 * 24 one day)
*/
private static long TIME_TO_LIVE = 0L;
/**
* 初始化 JPushClient
*
* @return
*/
public static void createCustomClient() {
ClientConfig clientConfig = ClientConfig.getInstance();
clientConfig.setApnsProduction(Boolean.valueOf(APNS_PRODUCTION)); //
development env
clientConfig.setTimeToLive(TIME_TO_LIVE);
jPushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
}
//设置推送通知
HashMap<String, String> map = new HashMap<String, String>();
map.put("pendId", pendId);// 事件 id
pushBuilder.setNotification(Notification.newBuilder().setAlert(title)
.addPlatformNotification(AndroidNotification.newBuilder().setTitle(
content).addExtras(map).build())
.addPlatformNotification(IosNotification.newBuilder().addExtras(map
).incrBadge(1).autoBadge()
.setAlert(IosAlert.newBuilder().setTitleAndBody(title,
null, content).build()).build())
.build());
return pushBuilder.build();
}
try {
String[] alias = {"1"};
JPushUtil.sendPushes("测试推送", "内容是有人分派一项任务给你了,快去处理吧",
"422", alias);
} catch (Exception e) {
e.printStackTrace();
}
}
}