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