1, the required jar bag
Aurora Java version of JDK Jpush-client-3.2.9.jar
Dependent Jar Pack Gson-2.6.2.jar
2. Sample Code
Package com.wqd;
Import cn.jpush.api.JPushClient;
Import Cn.jpush.api.push.PushResult;
Import Cn.jpush.api.push.model.Message;
Import Cn.jpush.api.push.model.Platform;
Import Cn.jpush.api.push.model.PushPayload;
Import cn.jpush.api.push.model.audience.Audience;
Import Cn.jpush.api.push.model.audience.AudienceTarget;
Import cn.jpush.api.push.model.notification.Notification;
public class Maintest {
public static void Main (string[] args) throws Exception {
String Mastersecret = "108fc87a27856a86dfaa8e5e";
String Appkey = "1430d4c79d5052ff8f778be2";
int maxretrytimes = 3;
Jpushclient jpushclient = new Jpushclient (Mastersecret, Appkey, maxretrytimes);
Pushpayload payload = Buildpushobject_all_all_alert ();
Pushresult result = Jpushclient.sendpush (payload);
}
/**
* Quickly build push objects: All platforms, all devices, alerts with content alert
*/
public static Pushpayload Buildpushobject_all_all_alert () {
Return Pushpayload.alertall ("This is OK.") ");
}
/**
* Build Push object: All platforms, push Target is alias "ALIAS1", alert content is alert.
*/
public static Pushpayload Buildpushobject_all_alias_alert () {
Return Pushpayload.newbuilder ()
. Setplatform (Platform.all ())
. Setaudience (Audience.alias ("ALIAS1"))
. Setnotification (Notification.alert (""))
. build ();
}
/**
* Build Push object: Platform is IOS, push target is "Tag1", "Tag_all" intersection
* Push content includes both notification and message-the notification message is alert, the angular number is 5, the notification sound is "happy", and the additional field from = "Jpush";
* Message content is msg_content. The notification is the APNS push channel.
* Messages are Jpush in-app message channels. APNS push Environment is "production" (The Library will be designated as development by default if not explicitly set)
*/
public static Pushpayload Buildpushobject_android_tag_alertwithtitle () {
Return Pushpayload.newbuilder ()
. Setplatform (Platform.android ())
. Setaudience (Audience.tag ("Tag1"))
. Setnotification (Notification.android ("ALERT", "TITLE", NULL)
. build ();
}
/**
* Build Push object: Platform is Andorid and IOS, push Target is ("Tag1" and "Tag2") and ("ALIAS1" and "ALIAS2" of the Set)
* Push content is-content is msg_content message, and additional field from = Jpush.
*/
public static Pushpayload Buildpushobject_ios_audiencemore_messagewithextras () {
Return Pushpayload.newbuilder ()
. Setplatform (Platform.android_ios ())
. Setaudience (Audience.newbuilder ()
. Addaudiencetarget (Audiencetarget.tag ("Tag1", "Tag2"))
. Addaudiencetarget (Audiencetarget.alias ("alias1", "ALIAS2"))
. Build ())
. Setmessage (Message.newbuilder ()
. Setmsgcontent ("Msg_content")
. Addextra ("from", "Jpush")
. Build ())
. build ();
}
}