11

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");
    }
}


}
rational
  • 111
  • 11
Dinu
  • 601
  • 3
  • 6
  • 26
  • 2
    Dear if you have downloaded "GCM package from SDK manager" then there are samples for Client, Server. Just check **android-sdk/extras/google/GCM** directory – Paresh Mayani Jul 13 '12 at 04:46
  • @PareshMayani http://chat.stackoverflow.com/transcript/message/4508859#4508859 but not able to find in sdk manager in extras folder – Khan Jul 13 '12 at 05:36
  • Quick question - in the method `register`, is the sender-ID (here: 555817657362) per-device or per-application (device independent)? – Gaurav Vaish May 14 '13 at 11:00
  • 1
    @MasterGaurav its per application – Dinu Sep 15 '14 at 11:07

4 Answers4

23

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

Community
  • 1
  • 1
HelmiB
  • 12,025
  • 5
  • 38
  • 65
6

"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.

farhanjk
  • 1,103
  • 10
  • 15
  • Link-only answers are strongly discouraged here at Stack Overflow. Instead, [it is preferable](http://meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – drs Jul 22 '14 at 01:41
  • 1
    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. – cV2 Sep 25 '14 at 16:11
5

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.

selsine
  • 2,833
  • 2
  • 19
  • 22
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

Chicowitz
  • 5,241
  • 5
  • 26
  • 36