0

I am Trying to fetch and push A notification (To inform the device to connect to the data source because it has been changed/Updated)

I read A lot of tutorials about it , and tried to apply it to help me in my case , but really i faced some problem understanding the GCM HOW IT Works

I've register at https://code.google.com/apis/console and take the SENDER ID AND APIKEY

Now I've Some Questions :

  1. do you register the device to the service every time we start the application or only for the first time ?

  2. do we use GCM for (only notify the device something happens) or to (notify and get the information about whats is changes) ?

  3. why this operation need (Client And Server) I mean (Client) it's OK Because he'll receive the push notification ,, but (Server What it Means Here) :( ,, because i think the server here will be the Google it self to notify the device

  4. In this Case When We Use A APIKEY

the Idea Is :

I've SQL Server Database on my web-site and have small android application (Dealing With it) with two users need when any user Add A record to the database notify the other user

Thanks In Advance ,,

Regards :)


Loai
  • 732
  • 16
  • 32

1 Answers1

1

1) You register with GCM only when you need to. E.g. When you call

GCMRegistrar.getRegistrationId(appContext);

And it returns a blank string. Typically this happens the first time you launch your app.

2) It depends on what the data you are trying to is and whether or not it will fit within the 4K payload limit. Take a look at the Send-to-Sync vs. Messages with Payload Google Help topic.

3) Your server is the server that sends the message to the GCM servers. The GCM servers then send the message down to the apps. Take a look at this blog post I wrote for a service that I helped create: http://blog.andromo.com/2012/how-does-airbop-push-messaging-work/ It should help explain how this works. In the explanation you can just substitute our servers with your own.

4) You send your API key as part of your message to the GCM servers as detailed here: http://developer.android.com/google/gcm/gcm.html#request

So in the following request:

Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA

{
  "registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."],
  "data" : {
    ...
  },
}

Authorization: key=YOUR_API_KEY

selsine
  • 2,813
  • 2
  • 21
  • 22
  • thank you so much (+1), **1-** I Understand that , the server will receive something from the device and it's send it backs to GCM and The GCM Will push A notification to another Device ? Is that Ok ? **2-** I think Depends on what you wrote above the server might be in the same app or it can be on a web-site (page) to receive from device and send it to GCM ? – Loai Dec 13 '12 at 09:18
  • Take a look at the blog post that I linked to. In a nutshell you app gets an ID from GCM when it registers and then sends that to your server. You server then includes that ID when sending messages to GCM. GCM uses that ID to direct the message to your app. – selsine Dec 13 '12 at 15:48
  • @sesline I've Read The Post but still need to understand the server functionality ... Can I put the server inside the client device to automaticely when i send something from the client goes directly to another device .. – Loai Dec 14 '12 at 15:54
  • Sure you could. The app would then send the message to GCM which would then distribute it to the rest of your apps. The difficulty with doing it in your app, is that the app would have to know all of the regisitrationID's that it needs to contact. You will still need some sort of server though, that is where the devices register. Something needs to store those registration IDs. – selsine Dec 14 '12 at 17:23
  • OK , thank you so much , (I'll Do that by Asp.net) that means i'll put a method in a web-service and call it from device app (but this method will take two arguments from me (**DEVICE_ID**,**msg**). so , **DEVICE_ID** here means what ? [http://stackoverflow.com/questions/11261718/gcm-push-notification-with-asp-net] – Loai Dec 14 '12 at 21:10
  • 1
    I'm not sure, I'm assuming the ID of the device? It depends on your implementation I think. – selsine Dec 17 '12 at 20:31
  • Yes , It seems like (`DEVICE-ID` = `Registration-ID`) http://stackoverflow.com/questions/13901132/push-notification-gcm-using-asp-net-the-notification-wasnt-received-browse – Loai Dec 17 '12 at 21:57