简体   繁体   中英

How to send Notification Message with gcm-server.jar

I am using the gcm-server.jar to send gcm Messages from Server because its easy to use. ( http://www.java2s.com/Code/Jar/g/Downloadgcmserverjar.htm ). Messages are sent with this code. This works fine:

Message msg = new Message.Builder().addData("message", message).build();
Sender sender = new Sender();
Result result = sender.send(msg, token, 5);
...

How can I send a GCM Message with Notification Payload like in this JSON:

 {"to":"token" ,
 "notification":{
 "sound":"default",
 "badge":"1",
 "title":"this is the title",
 "body":"this is the body"}}

You need to have a server set up where you parse these messages in JSON format so that GCM can process it accordingly.

Usually this depends on what server technology you are using. Also, you might want to check the validity of the library you referenced as GCM framework has been updated substantially.

Here 'sa good place to start.
And another good tutorial here . (although this one is older too but gives you understanding of server side implementation)

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM