Jpush simple Java server-side case implementation

Source: Internet
Author: User

First, laser push preparation work

1. Register Aurora to push developer account, create application:

2, complete the push settings, fill in the application name to submit the build installation package:

3, scan code installation simple test APK, view application information will have Appkey and master secret for push.

Second, the Java service side

The required jar packages and detailed integration can be viewed in the official documentation, which simply implements a simple notification or push message.

import Org.slf4j.logger;import Org.slf4j.loggerfactory;import cn.jiguang.common.resp.APIConnectionException; Import Cn.jiguang.common.resp.apirequestexception;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; Public classJpushutil {//AppKey and Mastersecret for uploading applications in the Aurora register//required, e.g. 466f7032ac604e02fb7bda89    Private StaticFinal String AppKey ="5fe124f6c597df4c3f375695"; //required, each application corresponds to a mastersecret    Private StaticFinal String Mastersecret ="4c1db9f46afe89520bdb2c59"; PrivateFinalStaticLogger Logger = Loggerfactory.getlogger (jpushutil.class); Private StaticJpushclient Jpush =NULL;  Public Static voidMain (string[] args) {String message="{\ "name\": \ "Jack\", \ "age\":"; //test Send message or notificationjpushsend (message); }         Public Static voidjpushsend (String message) {Logger.info ("enter Jpushsend."); Jpush=Newjpushclient (Mastersecret, AppKey); Pushpayload Payload=buildpushobject_all_all_alert_message (message); Pushresult Msgresult=NULL; Try{Msgresult=Jpush.sendpush (payload); } Catch(apiconnectionexception e) {e.printstacktrace (); } Catch(apirequestexception e) {e.printstacktrace (); }        if(NULL!=Msgresult) {System. out. println (Msgresult.getresponsecode ()); } Else{System. out. println ("unable to get data"); }}// Setplatform is used to set the platform,setaudience is used to set the push,setmessage means that the push is custom information,    Push notifications can be set to Pushpayload.alertall ("test"); Private Staticpushpayload buildpushobject_all_all_alert_message (String message) {returnPushpayload.newbuilder (). Setplatform (Platform.all ()). Setaudience (Audience.all ()). Setmessage ( Message.newbuilder (). Setmsgcontent (Message). Settitle ("Test"). Addextra ("Extra","Extra"). Build ()). build (); }}

Jpush simple Java server-side case implementation

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.