Aurora Push Java code sample __appcan

Source: Internet
Author: User

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 ();
}

}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.