Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud messaging - Sample Server

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


}
like image 739
Dinu Avatar asked Jul 13 '12 04:07

Dinu


People also ask

Is GCM still working?

The GCM server and client APIs were removed on May 29, 2019, and currently any calls to those APIs can be expected to fail. Google Cloud Messaging, deprecated April 10 2018, has been deactivated and removed from Google's APIs.

What is FCM server?

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost. Firebase. 339K subscribers. Introducing Firebase Cloud Messaging. 21/28.

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.


2 Answers

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

like image 154
HelmiB Avatar answered Sep 27 '22 18:09

HelmiB


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

like image 25
farhanjk Avatar answered Sep 27 '22 17:09

farhanjk