Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google cloud messaging sample [closed]

Does anyone have a sample gcm server side and android project? Preferably a tutorial that explains everything.

I have tried to have a look at the one included in the sample however I haven't been able to get it work.

I have a c2dm project which works both server side and android, but I don't know how to convert this to gcm.

I will be using gcm to push messages

any help would be appreciated

like image 337
Tuffy G Avatar asked Sep 13 '12 14:09

Tuffy G


People also ask

How does Google Cloud Messaging work?

PRO TIP: Google Cloud Messaging for Android (GCM) is a service that allows developers to send data from their servers to their users' devices, and vice versa. GCM is completely free, and you can use it to send or receive any data, up to 4kb in size. You can then add recipients, recipients' addresses, and messages.

Is Google Cloud Messaging free?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.

What is difference between FCM and GCM?

FCM is the new version of GCM under the Firebase brand. It inherits GCM's core infrastructure to make sure we continue to deliver messages reliably on Android, iOS and Chrome. Save this answer.

What is Collapse_key?

The collapse key parameter identifies a group of messages (for example, with collapse_key: updates available) that can be collapsed, so that only the last message is sent when delivery resumes. The feature helps you avoid sending the same messages when the device becomes active.


1 Answers

just follow this tutorial

hope it will help you.

GCM SERVER-SIDE (java code)

  public class GCMServerJava {

/**
 * @param args
 */
public static void main(String[] args) {

    Sender sender = new Sender(enter your App id);// app id



    Message message = new Message.Builder()
    .collapseKey("1")
    .timeToLive(3)
    .delayWhileIdle(true)
    .addData("message",
            "this text will be seen in notification bar!!").build();
    Result result;
    try {


        result = sender.send(message,"registration id which client get after registering device with google gcm service", 1);   


        System.out.println(result.toString());

        Message message1 = new Message.Builder()

        .build();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

like image 117
Prachi Avatar answered Sep 30 '22 18:09

Prachi