jpush初始化:
1、对android和ios设备发送
JPushClient jpush = new JPushClient(masterSecret, appKey);
2、对android和ios设备发送,同时指定离线消息保存时间
JPushClient jpush = new JPushClient(masterSecret, appKey, timeToLive);
3、指定某种设备发送
JPushClient jpush = new JPushClient(masterSecret, appKey, DeviceEnum.Android);
4、指定某种设备发送,同时指定离线消息保存时间
JPushClient jpush = new JPushClient(masterSecret, appKey, timeToLive, DeviceEnum.IOS);
参数说明:
发送消息:
代码示例:
1、发送带IMEI的通知
JPushClient jpush = new JPushClient(masterSecret, appKey);
//jpush.setEnableSSL(true);
int sendNo = 1;
String imei = "";
String msgTitle = "";
String msgContent = "";
MessageResult msgResult = jpush.sendNotificationWithImei(sendNo, imei, msgTitle, msgContent);
if (null != msgResult) {
if (msgResult.getErrcode() == ErrorCodeEnum.NOERROR.value()) {
System.out.println("发送成功, sendNo=" + msgResult.getSendno());
} else {
System.out.println("发送失败, 错误代码=" + msgResult.getErrcode() + ", 错误消息=" + msgResult.getErrmsg());
}
} else {
System.out.println("无法获取数据");
}
2、IOS设置通知铃声及badge
JPushClient jpush = new JPushClient(masterSecret, appKey);
Map<String, Object> extra = new HashMap<String, Object>();
IOSExtra iosExtra = new IOSExtra(1, "Windows_Logon_Sound.wav");//badge and sound
extra.put("ios", iosExtra);
MessageResult msgResult = jpush.sendNotificationWithAppKey(sendNo, msgTitle, msgContent, 0, extra);