Google Cloud messaging - Sample Server

13,351

Solution 1

You need to download via Android SDK. go to Window->Android SDK Manager. scroll down to extra and check "Google Cloud Messaging" and install.

after completed, you may check at : android-sdk/extras/google/gcm/samples

or you could try this (I've uploaded myself) : gcm

for server side, check on this answer : https://stackoverflow.com/a/11253231/554740

Solution 2

"curl" command line tool can be used to send messages to devices registered with GCM.

curl -X POST \
  -H "Authorization: key= <YOUR_AUTHORIZATION_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
  "registration_ids": [
    "<YOUR_DEVICE_TOKEN>"
  ],
  "data": {
    "message": "<YOUR_MESSAGE>"
  }
}' \
  https://android.googleapis.com/gcm/send

Please refer to this blog post for further details. http://www.zinniakhan.com/2014/07/check-google-cloud-messaging-gcm-client.html.

Solution 3

We have a sample client up on GitHub: https://github.com/indigorose/airbop-client (based on the GCM client sample), which works with our GCM-based service AirBop: http://www.airbop.com Which you can test with for free.

Solution 4

I found an open-source sender client for windows here: https://gcm.codeplex.com/

  • Device token can be found after you implement the GCM registration code and retrieve your registration ID via your client app (setup a breakpoint or print statement so that you are able to copy/paste this value, it's pretty long)
  • Auth key is found after you setup your project in Google's developer console

screenshot

Share:
13,351
Dinu
Author by

Dinu

I work as a android developer n a freelancer

Updated on June 15, 2022

Comments

  • Dinu
    Dinu almost 2 years

    I need a sample application for Google Cloud messaging. with a sample server to test my app. can any one help me on this?

    I need a sample server to test my code i already written the code but i dont know wheather it will work or not. i dont know server side coding so anyone could help me on this. here is my code

    intent service

    package com.example.pushnotificationsample;
    
    import android.content.Context;
    
    public class GCMIntentService extends GCMBaseIntentService {
    
    protected GCMIntentService(String senderId) {
        super(senderId);
        // TODO Auto-generated constructor stub
    }
    
    @Override
    protected void onError(Context arg0, String arg1) {
        // TODO Auto-generated method stub
    }
    
    @Override
    protected void onMessage(Context arg0, Intent msgIntent) {
        // TODO Auto-generated method stub
        Log.d("GCM", "RECIEVED A MESSAGE");
      //        String msg=msgIntent.getStringExtra("Message");
        Log.d("GCM", msgIntent.toString());
        // Get the data from intent and send to notificaion bar
    
    }
    
    @Override
    protected void onRegistered(Context arg0, String arg1) {
        // TODO Auto-generated method stub
    }
    
    @Override
    protected void onUnregistered(Context arg0, String arg1) {
        // TODO Auto-generated method stub
    }
    }
    

    my main activity

    package com.example.pushnotificationsample;
    
    import android.app.Activity;
    import com.google.android.gcm.GCMRegistrar;
    import android.os.Bundle;
    import android.util.Log;
    
    public class MainActivity  extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        GCMRegistrar.checkDevice(this);
       // GCMRegistrar.checkManifest(this);
        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
          GCMRegistrar.register(this, "555817657362");
          Log.v("Msg", "registered");
        } else {
          Log.v("Msg", "Already registered");
        }
    }
    
    
    }
    
  • drs
    drs almost 10 years
    Link-only answers are strongly discouraged here at Stack Overflow. Instead, it is preferable to include the essential parts of the answer here, and provide the link for reference.
  • cV2
    cV2 over 9 years
    works like a charm for me, please note!!! dont put any characters like (which need to be espaced) "It's me, some dummy message" into message ;) because it will produce u lots of pain.