// 对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;
}
} |
相关推荐
JPush极光推送 java
极光推送 JAVA服务端 jpush-client-3.2.8 与 集成源码 jpush-api-java-client-master
jpush极光推送,可用于socket通讯,可以发送通知和消息
极光推送所需jar包
JPush极光推送 ①官网:https://www.jpush.cn/ ②选择入门指南/实例与代码/服务器端 API 开发包与示例/Java开发包与使用示例/v3.2.8 - 新功能和优化/ 【jpush-client-3.2.8.zip】点击下载。 ③下载下来的压缩包为...
极光推送使用java后台接入demo,推送会通知到Android和Ios的手机通知栏
jpush极光推送帮助类,
java及成jpush极光推送所用到的JAR包, 欢迎各位大神下载
极光推送开发教程之服务器端代码.不含业务逻辑部分,你自己结合你的业务添加进去.zip
jpush极光推送全平台单发、群发(正式环境),下载后将JPushUtil.java中的APP_KEY、MASTER_SECRET换成自己的。 备注:没必要下载,下载demo然后增加 .setOptions(Options.newBuilder() .setApnsProduction(true) ....
一个jpush极光推送远程调用api简单的实例,方便那些用TP为App开发后台的人员用。很简单的,镶嵌到TP里面就可以了。 大家也可以到这里下载:http://www.jakehu.me/?p=38
消息推送,极光推送,php做服务器端的安卓消息推送.
一个简单的极光推送java服务器端的DEMO 一个简单的极光推送java服务器端的DEMO 一个简单的极光推送java服务器端的DEMO 一个简单的极光推送java服务器端的DEMO 一个简单的极光推送java服务器端的DEMO 一个简单的极光...
用于极光推送jar包,有需要的可以去官方文档下载,https://github.com/jpush/jpush-api-java-client
很好的服务器向服务器端推送很好的例子 解决了大部分朋友 在服务器像客户端推送消息的问题
极光推送,使得开发者可以即时地向其应用程序的用户推送通知或者消息,与用户保持互动,从而有效地提高留存率,提升用户体验。平台提供整合了Android推送、iOS推送的统一推送服务。 产品特点 多种推送方式 Push ...
JPush(极光推送SDK)
极光推送的android客户端和Java服务器端的例子.非常好用。 绝对能运行,但需要你把key和masterSecret改成你自己的。
此为极光推送工具类,其包含极光推送、认证、分享、魔链、短信等功能。
请看博客介绍:http://blog.csdn.net/shakespeare001/article/details/50266875