// 对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);
|
masterSecret |
String | 必须 | Portal上注册应用时生成的 masterSecret |
appKey | String | 必须 | Portal上注册应用时生成的 appKey |
timeToLive | long | 可选 | 保存离线消息的时长。秒为单位。最多支持10天(864000秒)。 |
DeviceEnum | Enum | 可选 | 指定的设备。 可选值:DeviceEnum.Android, DeviceEnum.IOS。 不填或者null值为同时支持 Android 与 iOS。 |
发送消息
JPushClient公共方法
setEnableSSL | boolean enableSSL (true为使用ssl, 默认为不使用ssl) | 是否启动ssl安全连接 |
sendNotificationWithImei |
int sendNo(发送编号), String imei (IMEI字符串) , String msgTitle (消息标题/通知标题) , String msgContent (消息内容/通知内容) |
发送带IMEI的通知 |
sendNotificationWithImei | int sendNo , String imei , String msgTitle , String msgContent , int builderId (自定义通知栏样式Id) , Map<String, Object>extra (附属信息) |
自定义通知栏(没有则填写0) 以及传递附属信息 |
sendCustomMessageWithImei |
int sendNo , String imei , String msgTitle , String msgContent |
发送带IMEI的消息 |
sendCustomMessageWithImei | int sendNo , String imei , String msgTitle , String msgContent, String msgContentType (消息内容类型,原样返回), Map<String, Object> extra |
用户自定义消息类型, 以及传递附属信息 |
sendNotificationWithTag |
int sendNo , String tag (Tag字符串) , String msgTitle , String msgContent |
发送带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包集成到项目中,毕竟把这份源码原样考到项目中太臃肿,能有什么简便的方法吗?跪谢
支持(0)
反对(0)
http://pic.cnblogs.com/face/544289/20130803090206.png
#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;可以加我旺旺 浩气
支持(0)
反对(0)
http://pic.cnblogs.com/face/u436443.jpg?id=10203124
#3楼 2015-04-28 11:01 just__chao
@菜鸟的春天
好的收到,真心感谢!!
好的收到,真心感谢!!
支持(0)
反对(0)
http://pic.cnblogs.com/face/544289/20130803090206.png
#4楼 2015-06-03 12:04 朱啊朱
你好,我刚在弄极光推送,但是我的下载了一份服务端的代码,把AppKey都已经更改为我的了,但是返回的都是1011,不知道应该怎么解决,能帮助我一下吗?
支持(0)
反对(0)
#5楼[楼主] 2015-06-03 13:30 菜鸟的春天
@朱啊朱
1011:没有满足条件的推送目标;这个是因为没有客户端!可以先用手机或者模拟器启动jpush client(在自己的应用里使用jpush)
1011:没有满足条件的推送目标;这个是因为没有客户端!可以先用手机或者模拟器启动jpush client(在自己的应用里使用jpush)
支持(0)
反对(0)
http://pic.cnblogs.com/face/u436443.jpg?id=10203124
#6楼 2015-06-03 14:09 朱啊朱
@菜鸟的春天
那应该怎么模拟呢?可以教我一下吗
那应该怎么模拟呢?可以教我一下吗
支持(0)
反对(0)
#7楼[楼主] 2015-06-04 10:30 菜鸟的春天
@朱啊朱
参考官方文档 http://docs.jpush.io/client/android_tutorials/
参考官方文档 http://docs.jpush.io/client/android_tutorials/
支持(0)
反对(0)
http://pic.cnblogs.com/face/u436443.jpg?id=10203124
#8楼 2015-07-07 23:24 flykiss
大神,为什么我用最新的版本的没有sendCustomMessageWithTag呢
支持(0)
反对(0)
#9楼 2015-07-16 16:51 abc搬运工
你好,java写定向推送要应该怎么写,如果有代码展示一下就最好了,如果你会的话望指点一下,感激不尽啊!
支持(0)
反对(0)
#10楼32291362015/7/16 16:56:36 2015-07-16 16:56 依漠
原文地址: http://www.cnblogs.com/zhanghaoh/archive/2013/02/20/2919282.html