UnExpected reply from GCM Server when i am sending the Expected URL - android

**Question (i)**
I have registered my android app in my mobile (Samsung Galaxy Pop) i am recieved a
registrataion_id
APA91bG9NI4U2jr4sUn1HLy5nHMFe1e0JOTgOoZv1Px**********************************
when i sent this registration_id to server side code which is refrenced from here
here i used function SendNotification having 2 parameters
My Registration_ID
My Message Which i want to show on notufication
http://www.codeproject.com/Tips/434338/Android-GCM-Push-Notification
I hit the GCM- Server and the result I got is
id=0:1368258967353783%978fee9266d6cf16
I did not understand what does this response means ? is it good ? bad ?
Question (ii)
if mobile device gets registration id from gcm server is it registered or still waiting for server side to send the Registration ID to GCM Server
Please help !! , Thanks in advance

Answer to(i)
The data you are getting is on plain text format and the data is refering to the message id. In this case the message was correctly sended.
To understand how it works visit this page GCM Architectural Overview
Answer to (ii)
The way GCM works it's
Your device request a registretion to GCM services.
Device is registered correctly by receiving the regId.
You send that regId to your server to receive push notifications.
Server saves the data
Servers wants to send a message to that device, sends a mesage using GCM services.
The device, if it is online, receives it and knows wich app haves to start.
The app receives the message.
On the same website you have further explanation, by the way start reading from getting started section.

Related

How to send Google cloud messaging message to other devices without logic on 3rd party server

I am trying to make a simple messaging app that has a mysql and php server with an android app. My back end revolves around mysql to store and php to communicate from the database to the device and vise versa.
Now, what I am trying to accomplish is this: sending device->GCM->target device.
What I had in mind was that the database I created stores the gcm Id for all user. That way, when a user wants to send a message, their app sends a message to my database to be stored and retrieves the targets gcm Id and then sends the targets gcm id to the gcm servers to create the push notificiation. When the target receives the gcm message, it sends a response to the database to receive the actual sent message.
Is this possible, and how would I go about doing this?
I already have a gcm receiver implemented from here:
https://github.com/codepath/android_guides/wiki/Google-Cloud-Messaging
No. Don't do it.
For any internet connected device (server or mobile) to request a push to a device, it needs to send a POST request to the GCM address (https://gcm-http.googleapis.com/gcm/send) passing the server API key and the device GCM reg id which should receive the message. And having any of those values available on a device is a security risk for your application.
Having your registration ID, means ppl could easily "copy" your ID and start sending messages from their servers on your behalf.
The GCM device registraion ID, means anyone could start spaming your users, and you certainly don't want that.
You could look into GCM Upstream (https://developers.google.com/cloud-messaging/upstream) but that only means your client code will be easier, as it's as simple as calling gcm.send(String);, but you still have to handle that on your server application.
The correct way is to have on your server a table that maps userId with gcmRegId and have devices send to your server messages to their desired userId. Your server should process one device "send" message and create a push to the other device. That logic should be fairly simple on the server side, after you already have a whole chat application developed.

Flowchart of messages in GCM using the upstream messaging

I am trying to understand the concept of gcm upstream messaging.
Well what I came to know till now after browsing for hours is this :
1)My client app sends upstream message to gcm server.2)GCM server then sends it to my 3rd party app server.3rd party app server responds to it my sending ACK to GCM server.3)Then GCM server echoes the message to the recipient device(recipient Id is included in the upstream message sent from the app).
I don't if its what actually happens.
Now that I am sure that in some step GCM server sends mesaage to my server, how actually GCM server
sends message to my app server. How does it come to know about my app server as there is nowhere where we put my server's address
I have searched the whole Internet but couldn't find anything about this.I have gone through several SO questions but I couldnot find my answer.
I want to know the entire series of steps what happens during this entire process. I am very confused.I want to know the entire concept and what's going on behind all this.
Any detailed explanation with all steps will be appreciated.
To inform I have read the Google docs.
You have much of the flow correct but I think another read of the Docs will clear things up.
Your application server must act as an XMPP client, and connect to CCS (GCM's XMPP server). Your server connecting to CCS is how GCM knows the "address" of your server.
Cleaning up the flow you suggested:
Your app server connects to GCM's CCS.
Your client app (android app) gets a registration token.
Your client app (android app) sends that token to your app server.
Your client app send upstream message to GCM.
GCM fwds that message to your application server.
Your application server send Ack to CCS.
Your application server handles the received message.
Note the above flow is a possible one, there are many others, also downstream messages are not part of the flow. Again refer to the docs for more details.

GCM Extras Error: "TooManyMessages"

I'm trying to follow the official guide for setting up a GCM client.
The Situation
After having set up everything just like in the guide,
I am able to send a message over to the GCM, using:
gcm.send
Then, exactly as should happen, the broadcaster calls to my intent's OnReceived procedure.
So far so good.
The Problem
Upon receiving the actual data, meaning - the intent's extras as a Bundle object, a problem occurs.
The extras' content (toString) contains an error:
Bundle[{error=TooManyMessages,
message_type=send_error,
google.message_id=1,
android.support.content.wakelockid=1}
The Meaning
Now, I've done my research, but came up with no practical answers. Only an explanation as to what is happening. Here is the problem, and its explanation:
This means that too many messages were stored in the GCM server for a single device without being delivered (which might happen if your device was offline while many messages were sent by your server).
Once the number of such messages reaches the limit, which is 100 if you don't use a collapse key, they are deleted from the GCM server, and you get that error message, which informes you your device should sync with your server in order to get the lost messages.
The Question
So, according to the answer, I am to sync my device with the server. How, exactly?
Also note, I have not created a GCM server. I'm only using the official GCM client implementation.
Thanks in advance to those who help!
-P
It's unclear what you are trying to send and to whom. The gcm.send method sends a message from your application to your server. For the message to big delivered, you must implement a server that connects to the GCM Cloud Connection Server. Since you don't have a server, GCM can't send the message to your server, and stores the message. Once too many messages are stored, you get the TooManyMessages error.
You must implement a server in order to use GCM. If you only want to send messages from the server to your app, you can use the simpler GCM HTTP API. If you need to send messages from your app to your server, you should use the GCM CCS API.
The answer you are referring to describes a different situation in which you can get TooManyMessages error (when the server sends many messages to the same device, but GCM can't deliver those messages), but it's not relevant to your situation.

GCM Server knowing of successful delivery

As far I as know, upon successful posting a notification to GCM Server, it will return a status code of 200 and a response as such id=1:2342.
However, according to their documentation, this does not guarantee successful delivery to the device. Just a successful status of delivering the notification to the GCM server.
So my question is, is there a way for me to know that the notification has been sent to the phone successfully? Is there a Delivery Notification returned by GCM to my side upon successful delivery? If not, does any of you guys have any ideas on keeping track of those?
Thanks.
GCM does not notify your server when the message is sent to the phone.
If you require that functionality, you'll have to implement it yourself. You can attach a message identifier field to the GCM message. When the message arrives to the phone, your app will send that message identifier back to your server (using an HTTP request), to acknowledge that it received the message.

Android C2DM Registration Id Change Frequency

I have built and Android app (not in the Market yet) and I am struggling to figure out why C2DM is failing. I am able to register my device, and I get back a registration Id.
I have built a server app that submits the request to google's C2DM server and I get back a 200 response and a message id. (Success). The issue is, my device never gets the messages.
One of the things that surprises me is that if I try to register a device twice within seconds I get back a different registration id. Most likely they use time as a seed.
Is it normal for this registration id to change so frequently? Any clues / advice (I read the guidelines already)?
Cheers...
Note:
I do not have a sim card and all I use is a corporate WiFi network. My last hope is that maybe port 5228 is closed on my network.
Google says that C2DM will change anytime. So you have to update your server with the correct registration id for the device. If the id server has doesnt match the one which google sent to your device, it will not be able to deliver the push.
So as a golden rule, "always update the server with the latest c2dm registration id as soon as you get it"
if Google replies with 200, the body should contain an id. if there is an error, there will be an error in the body. the error codes are given below.
QuotaExceeded — Too many messages sent by the sender. Retry after a while.
DeviceQuotaExceeded — Too many messages sent by the sender to a specific device. Retry after a while.
MissingRegistration — Missing registration_id. Sender should always add the registration_id to the request.
InvalidRegistration — Bad registration_id. Sender should remove this registration_id.
MismatchSenderId — The sender_id contained in the registration_id does not match the sender id used to register with the C2DM servers.
NotRegistered — The user has uninstalled the application or turned off notifications. Sender should stop sending messages to this device and delete the registration_id. The client needs to re-register with the c2dm servers to receive notifications again.
MessageTooBig — The payload of the message is too big, see the limitations. Reduce the size of the message.
MissingCollapseKey — Collapse key is required. Include collapse key in the request.
This info is from http://code.google.com/android/c2dm/#testing
Yes as Rihan said every time you registered your device you will get a new registration ID.and if you are getting registration ID that your c2dm is successfully implemented from google server.Now you have to send this ID to your server .And by using this ID you have send push notification to your device.
Now you will get message in OnReceive() method of C2DReceiver and you have to handle this message(May you give a notification to user)
The issue was that port 5228 was closed on the network I was using.
I had a similar problem, the issue was in the app I wasn't sending the right email address used to register for the C2DM messaging. So it kept failing.
So check if you are sending the correct email address as the senders email address when registering for C2DM from the device that is the email address registered with google for push notifications.
Although Rihan is correct. The registration id changes every time. The reason why I was not getting the messages is because the port was locked.
For other googlers, make sure 5228 is open before you go mad...

Categories

Resources