简体   繁体   中英

GCM sending message using java

Using nodejs and node-gcm I'm sending message to my android client using this code

var sender = new gcm.Sender('API KEY');
sender.send(message, regId, function(err, result) {
         if (err) console.log("error");
         else console.log("Message sent! :)");

There is something similar on Java? I found this

Sender sender = new Sender(GCM_API_KEY);
try {
        Result res = sender.send(message, "token", 3);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

But with the Java Sender I can't set the client id. How can I do?

There is no client id needed for sending a GCM message with the Sender class. All you need are the API key and the Registration ID (to be placed where you wrote "token" ).

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