Google Cloud messaging - Sample Server
Asked Answered
D

4

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


}
Daly answered 13/7, 2012 at 4:34 Comment(4)
Dear if you have downloaded "GCM package from SDK manager" then there are samples for Client, Server. Just check android-sdk/extras/google/GCM directoryAllseed
@PareshMayani chat.stackoverflow.com/transcript/message/4508859#4508859 but not able to find in sdk manager in extras folderGlassman
Quick question - in the method register, is the sender-ID (here: 555817657362) per-device or per-application (device independent)?Chevalier
@MasterGaurav its per applicationDaly
V
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://mcmap.net/q/125323/-gcm-with-php-google-cloud-messaging

Viand answered 15/9, 2012 at 12:53 Comment(0)
F
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.

Fritz answered 22/7, 2014 at 1:22 Comment(2)
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.Amphi
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.Bcd
B
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.

Berstine answered 30/11, 2012 at 16:26 Comment(0)
P
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

Policewoman answered 3/4, 2014 at 21:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.