// 对android和ios设备发送
JPushClient jpush =
new
JPushClient(masterSecret, appKey);
// 对android和ios设备发送,同时指定离线消息保存时间
JPushClient jpush =
new
JPushClient(masterSecret, appKey, timeToLive);
// 指定某种设备发送
JPushClient jpush =
new
JPushClient(masterSecret, appKey, DeviceEnum.Android);
// 指定某种设备发送,并且指定离线消息保存时间
JPushClient jpush =
new
JPushClient(masterSecret, appKey, timeToLive, DeviceEnum.IOS);
|
Parameter name parameter type option content description
masterSecret |
String | must | masterSecret generated when the application is registered on the Portal |
appKey | String | must | appKey generated when the application is registered on the Portal |
timeToLive | long | optional | How long to save offline messages. seconds. Up to 10 days (864000 seconds) are supported. |
DeviceEnum | Enum | optional | specified device. Optional values: DeviceEnum.Android, DeviceEnum.IOS. Leave blank or null to support both Android and iOS. |
send messages
JPushClient public method
method name parameter list (required) method description
setEnableSSL | boolean enableSSL (true to use ssl, default to not use ssl) | whether to enable ssl secure connection |
sendNotificationWithImei |
int sendNo (send number), String imei (IMEI string) , String msgTitle (message title/notification title) , String msgContent (message content/notification content) |
Send notification with IMEI |
sendNotificationWithImei | int sendNo , String imei , String msgTitle , String msgContent , int builderId (custom notification bar style ID) , Map<String, Object>extra (attached information) |
Customize the notification bar (fill in 0 if not) and pass auxiliary information |
sendCustomMessageWithImei |
int sendNo , String imei , String msgTitle , String msgContent |
Send message with IMEI |
sendCustomMessageWithImei | int sendNo , String imei , String msgTitle , String msgContent, String msgContentType (message content type, returned as-is), Map<String, Object> extra |
User-defined message types, and delivery of auxiliary information |
sendNotificationWithTag |
int sendNo , String tag (Tag字符串) , String msgTitle , String msgContent |
Send a notification with a tag |
sendNotificationWithTag | int sendNo , String tag , String msgTitle , String msgContent , int builderId , Map<String, Object>extra |
自定义通知栏(没有则填写0) 以及传递附属信息 |
sendCustomMessageWithTag |
int sendNo , String tag , String msgTitle , String msgContent |
发送带Tag的消息 |
sendCustomMessageWithTag |
int sendNo , String tag , String msgTitle , String msgContent , String msgContentType , Map<String, Object> extra |
用户自定义消息类型, 以及传递附属信息 |
sendNotificationWithAlias |
int sendNo , String alias (Alias字符串) , String msgTitle , String msgContent |
发送带Alias的通知 |
sendNotificationWithAlias | int sendNo , String alias (Alias字符串) , String msgTitle , String msgContent , int builderId , Map<String, Object>extra |
自定义通知栏(没有则填写0) 以及传递附属信息 |
sendCustomMessageWithAlias |
int sendNo , String alias , String msgTitle , String msgContent |
发送带Alias的消息 |
sendCustomMessageWithAlias | int sendNo , String alias , String msgTitle , String msgContent , String msgContentType , Map<String, Object> extra |
用户自定义消息类型, 以及传递附属信息 |
sendNotificationWithAppKey |
int sendNo , String msgTitle , String msgContent |
发送通知给AppKey的所有用户 |
sendNotificationWithAppKey | int sendNo , String msgTitle , String msgContent , int builderId , Map<String, Object>extra |
自定义通知栏(没有则填写0) 以及传递附属信息 |
sendCustomMessageWithAppKey |
int sendNo , String msgTitle , String msgContent |
发送带AppKey的消息 |
sendCustomMessageWithAppKey | int sendNo , String msgTitle , String msgContent , String msgContentType , Map<String, Object> extra |
用户自定义消息类型, 以及传递附属信息 |
代码示例
代码示例-发送带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(
"无法获取数据"
);
}
|
代码示例-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);
|
MessageResult 类
公共方法 方法用途
getSendno |
消息发送成功后,按客户端传输的sendNo原样返回 |
getErrcode |
错误代码,代码定义参考ErrorCodeEnum |
getErrmsg | 返回错误消息的描述 |
ErrorCode 类
错误代码-ErrorCodeEnum
package
cn.jpush.api;
public
enum
ErrorCodeEnum {
//没有错误,发送成功
NOERROR(
0
),
//系统内部错误
SystemError(
10
),
//不支持GET请求
NotSupportGetMethod(
1001
),
//缺少必须参数
MissingRequiredParameters(
1002
),
//参数值不合法
InvalidParameter(
1003
),
//验证失败
ValidateFailed(
1004
),
//消息体太大
DataTooBig(
1005
),
//IMEI不合法
InvalidIMEI(
1007
),
//appkey不合法
InvalidAppKey(
1008
),
//msg_content不合法
InvalidMsgContent(
1010
),
//没有满足条件的推送目标
InvalidPush(
1011
),
//IOS不支持自定义消息
CustomMessgaeNotSupportIOS(
1012
);
private
final
int
value;
private
ErrorCodeEnum(
final
int
value) {
this
.value = value;
}
public
int
value() {
return
this
.value;
}
}
|
posted on 2013-02-20 19:00 菜鸟的春天 阅读(30163) 评论(10) 编辑 收藏
评论
#1楼 2015-04-27 20:02 just__chao
大牛你好,按照你的步奏可以成功推送消息到手机上,现在怎么把这个Jpush ApI捣成一个jar包集成到项目中,毕竟把这份源码原样考到项目中太臃肿,能有什么简便的方法吗?跪谢
#2楼[楼主] 2015-04-28 10:55 菜鸟的春天
@just__chao
可以使用maven,可以使用jpush-client的最新版本3.1.3;如果你使用的ant或者没有使用类似构建工具, http://docs.jpush.io/resources/#sdk_1 下载最新sdk;还有一个最简单的方法,jpush已退出restfull api,可以使用restfull api开发自己的api;可以加我旺旺 浩气
可以使用maven,可以使用jpush-client的最新版本3.1.3;如果你使用的ant或者没有使用类似构建工具, http://docs.jpush.io/resources/#sdk_1 下载最新sdk;还有一个最简单的方法,jpush已退出restfull api,可以使用restfull api开发自己的api;可以加我旺旺 浩气
#3楼 2015-04-28 11:01 just__chao
@菜鸟的春天
好的收到,真心感谢!!
好的收到,真心感谢!!
#4楼 2015-06-03 12:04 朱啊朱
你好,我刚在弄极光推送,但是我的下载了一份服务端的代码,把AppKey都已经更改为我的了,但是返回的都是1011,不知道应该怎么解决,能帮助我一下吗?
#5楼[楼主] 2015-06-03 13:30 菜鸟的春天
@朱啊朱
1011:没有满足条件的推送目标;这个是因为没有客户端!可以先用手机或者模拟器启动jpush client(在自己的应用里使用jpush)
1011:没有满足条件的推送目标;这个是因为没有客户端!可以先用手机或者模拟器启动jpush client(在自己的应用里使用jpush)
#6楼 2015-06-03 14:09 朱啊朱
@菜鸟的春天
那应该怎么模拟呢?可以教我一下吗
那应该怎么模拟呢?可以教我一下吗
#7楼[ Landlord ] 2015-06-04 10:30 Spring of a rookie
#8 Floor 2015-07-07 23:24 flykiss
God, why do I use the latest version without sendCustomMessageWithTag?
#9 Floor 2015-07-16 16:51 abc porter
Hello, how to write directional push in java, it would be best if there is a code to show it, if you can give me some pointers, thank you very much!
#10th floor 2015-07-16 16:56 Yimo
Original address:
http://www.cnblogs.com/zhanghaoh/archive/2013/02/20/2919282.html