// 對(duì)android和ios設(shè)備發(fā)送
JPushClient jpush = new JPushClient(masterSecret, appKey);
// 對(duì)android和ios設(shè)備發(fā)送,同時(shí)指定離線消息保存時(shí)間
JPushClient jpush = new JPushClient(masterSecret, appKey, timeToLive);
// 指定某種設(shè)備發(fā)送
JPushClient jpush = new JPushClient(masterSecret, appKey, DeviceEnum.Android);
// 指定某種設(shè)備發(fā)送,并且指定離線消息保存時(shí)間
JPushClient jpush = new JPushClient(masterSecret, appKey, timeToLive, DeviceEnum.IOS);
|
參數(shù)名稱 | 參數(shù)類型 | 選項(xiàng) | 內(nèi)容說明 |
masterSecret
|
String |
必須 |
Portal上注冊應(yīng)用時(shí)生成的 masterSecret |
appKey |
String |
必須 |
Portal上注冊應(yīng)用時(shí)生成的 appKey |
timeToLive |
long |
可選 |
保存離線消息的時(shí)長。秒為單位。最多支持10天(864000秒)。 0 表示該消息不保存離線。即:用戶在線馬上發(fā)出,當(dāng)前不在線用戶將不會(huì)收到此消息。 此參數(shù)不設(shè)置則表示默認(rèn),默認(rèn)為保存1天的離線消息(86400秒)。
|
DeviceEnum |
Enum |
可選 |
指定的設(shè)備。 可選值:DeviceEnum.Android, DeviceEnum.IOS。 不填或者null值為同時(shí)支持 Android 與 iOS。 |
發(fā)送消息
JPushClient公共方法
方法名稱 | 參數(shù)列表(必須) | 方法說明 |
setEnableSSL |
boolean enableSSL (true為使用ssl, 默認(rèn)為不使用ssl) |
是否啟動(dòng)ssl安全連接 |
sendNotificationWithImei
|
int sendNo(發(fā)送編號(hào)), String imei (IMEI字符串) , String msgTitle (消息標(biāo)題/通知標(biāo)題) , String msgContent (消息內(nèi)容/通知內(nèi)容) |
發(fā)送帶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 |
發(fā)送帶IMEI的消息 |
sendCustomMessageWithImei |
int sendNo , String imei , String msgTitle , String msgContent, String msgContentType (消息內(nèi)容類型,原樣返回), Map<String, Object> extra |
用戶自定義消息類型, 以及傳遞附屬信息 |
sendNotificationWithTag
|
int sendNo , String tag (Tag字符串) , String msgTitle , String msgContent |
發(fā)送帶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 |
發(fā)送帶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 |
發(fā)送帶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 |
發(fā)送帶Alias的消息 |
sendCustomMessageWithAlias |
int sendNo , String alias , String msgTitle , String msgContent , String msgContentType , Map<String, Object> extra |
用戶自定義消息類型, 以及傳遞附屬信息 |
sendNotificationWithAppKey
|
int sendNo , String msgTitle , String msgContent |
發(fā)送通知給AppKey的所有用戶 |
sendNotificationWithAppKey |
int sendNo , String msgTitle , String msgContent , int builderId , Map<String, Object>extra |
自定義通知欄(沒有則填寫0) 以及傳遞附屬信息 |
sendCustomMessageWithAppKey
|
int sendNo , String msgTitle , String msgContent |
發(fā)送帶AppKey的消息 |
sendCustomMessageWithAppKey |
int sendNo , String msgTitle , String msgContent , String msgContentType , Map<String, Object> extra |
用戶自定義消息類型, 以及傳遞附屬信息 |
代碼示例
代碼示例-發(fā)送帶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( "發(fā)送成功, sendNo=" + msgResult.getSendno());
} else {
System.out.println( "發(fā)送失敗, 錯(cuò)誤代碼=" + msgResult.getErrcode() + ", 錯(cuò)誤消息=" + msgResult.getErrmsg());
}
} else {
System.out.println( "無法獲取數(shù)據(jù)" );
}
|
代碼示例-IOS設(shè)置通知鈴聲和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
|
消息發(fā)送成功后,按客戶端傳輸?shù)膕endNo原樣返回 |
getErrcode
|
錯(cuò)誤代碼,代碼定義參考ErrorCodeEnum |
getErrmsg |
返回錯(cuò)誤消息的描述 |
ErrorCode 類
錯(cuò)誤代碼-ErrorCodeEnum
package cn.jpush.api;
public enum ErrorCodeEnum {
//沒有錯(cuò)誤,發(fā)送成功
NOERROR( 0 ),
//系統(tǒng)內(nèi)部錯(cuò)誤
SystemError( 10 ),
//不支持GET請(qǐng)求
NotSupportGetMethod( 1001 ),
//缺少必須參數(shù)
MissingRequiredParameters( 1002 ),
//參數(shù)值不合法
InvalidParameter( 1003 ),
//驗(yàn)證失敗
ValidateFailed( 1004 ),
//消息體太大
DataTooBig( 1005 ),
//IMEI不合法
InvalidIMEI( 1007 ),
//appkey不合法
InvalidAppKey( 1008 ),
//msg_content不合法
InvalidMsgContent( 1010 ),
//沒有滿足條件的推送目標(biāo)
InvalidPush( 1011 ),
//IOS不支持自定義消息
CustomMessgaeNotSupportIOS( 1012 );
private final int value;
private ErrorCodeEnum( final int value) {
this .value = value;
}
public int value() {
return this .value;
}
}
|
|