I have read the tutorial of C2DM from given link
C2DM
I have followed the steps and able to obtain registration ID , authenticaton token for my device .but I don't understand how the C2DM server will come to know to whom the message is to be delivered.
When I send the message it is received on the same device , but i want to send this to other emulator.so I want to know that for this whether I have to make another applicatin with the same content or I can launch two emulators from the same appliaction and send messages from one to another .
Now my main question is :
when I give the registration Id And token it's actually of the sender's or the receiver's
whether I have to make another applicatin with the same content or I can launch two emulators from the same appliaction and send messages from one to another .
You should be able to just make one application and use two different emulators.
Now my main question is : when I give the registration Id And token it's actually of the sender's or the receiver's
Let me see if I understand you correctly here. You want to send a message from one device to the other right? Well you can't contact the other device directly. The best you can do is have the sending device post a message to the server with the id of the device you want to send it to. Note this probably won't be the other devices C2DM id (that could change for what ever reason), but rather some sort of name for which your sever will then have to resolve the C2DM id. Then, when the server gets the message, it figures out the id of the phone to send it to, sends a push to the recipient's phone, and then the recipients's phone downloads the data.
Does that make sense?
Related
While building my first Android app (a simple game), I came across this (most probably newbie) problem:
my app needs to send a message to a contact (chosen from contact list) via my own server.
same app installed on this contact's device, needs to retrieve this message.
The problem I am facing is contact "identification". How can the app identify a contact such that one device sends a message for this "ID", and another device polls for messages intended the same "ID?
Maybe there is some kind of ID associated with a contact having an Android device?
Thanks (and sorry for newbie question :)
You can try push notifications service, by using the google cloud messaging.
From the first device you can send an http request containing message to a server that manages the request and sends message to the second device, or to more than one device.
You can find a tutorial here
https://developers.google.com/cloud-messaging/
For the application that I am working I need to integrate Google Cloud Messaging. After playing a little with different examples, I was able to send and receive a notification on my deivce.
However, I have come across an interesting situation. As I know (please correct me if I'm wrong), the registration_id is issued per device and per application.
The application that I'm working supports login functionality. When the application is installed and the user logs in for the first time (let it be "UserA"), I request the registration_id from GCM which then I send it to my server.
Now imagine that UserA logs out and gives his device to some UserB to log in. With other words, UserB logs in using UserA's device.
The problem is that if meanwhile UserA receives a notification, UserB will be able to intercept it. And if UserB receives a notification, he won't be able to receive it.
This seems normal because the registration_id is per device and per application, but it does not seem reasonable for my case.
So I'm asking if there is a way I could make the registration_id to be dependent of some user id (besides the device and app)? Or how could I make such that the logged in user to receive only his own notifications?
Yes its true that you have one google registration ID for the app per device.
But you can always register and unregister users at your own Server that will actually send messages to GCM and GCM will send this to the registered devices.
Define some interfaces for your Server like registerOnServer and unRegisteronServer , send some unique value for each user on this interface.
So, in your case, when A use Log ins , regitration is done on GCM first and register the user on your Server with registerOnServer inteface and while the user is logged in send notifications pertaining to him to GCM to be send to the device.
When A logs out, unregister him using unRegisterServer and do not send any messages from your Server to GCM as A is unregistered.
So,now if B Logs in even with the same device , register him at your Server and send his messages.
This shall solve your problem!
I am trying to write an application which notifies a cellphone using GCM. I was able to implement basic functionality, but there is one question I'm still unsure of
As I understand, the flow goes like this:
Device start up
Device registers, obtains registration id
Server gets the knowledge of registration id on device
Server is using it's API key + registration id to send payload to device
Device receives payload.
One thing which is unclear to me is: what is a proper methodology to implement step #3?
I could not find any way to obtain a list of registered devices. Lets imagine, I am using GCM for a purpose of posting to a known device, and I could email that ID to myself and then register it on the server manually. But as I understand, it expires.
So, it there an expectation that I have to keep re-registering and somehow notifying server every time it happens?
Yes, your app on device must send registration ID to your server application in order for server to be able to send GCM messages. See third point in Enabling GCM.
For sending the same message to 100 devices via c2dm,
We need to do the following things,
1. get registration of each device that you need to send messages.
2. initiate 100 request one for each device and send it to c2dm.
Am i correct?
Do we really need to send 100 request one for each device. one request containing registration id of each device?
Is there any way that i can send all the device's registration ids in a single request with the message? so that with that request, c2dm will broadcast or push that common message to all 100 devices with that registration ids that it obtained in a single request?
C2dm does not allow batch sending until now. So you still have to send them for each device.
c2dm doesnt allow batch sending. even for my application i have been sending messages with different ids, by storing the ids in a database and retrieving them in a loop. i dont think there is any better solution.
So I have a situation which I didn't think would happen based on my understanding of the registration My understanding:
Phone Registers with google gets registration_id, send registration_id to the server, use registration_id when sending out push notifications. If registration_id is updated by google, they will send a new registration broadcast.
However, I have case where a phone was registered, and was successfully receiving push notifications, but than one day the server goes to send a push notification to the phone and I get a error "NotRegistered" which would suggest the registration_id refreshed but did not get propagated through the system properly, whether it be on the phone side or the server side.
My question is has anyone else hand issues like this? What is the best approach to making sure this doesn't happen?
From the Android Cloud to Device Messaging Framework documentation:
Note that Google may periodically refresh the registration ID, so you should design your application with the understanding that the REGISTRATION Intent may be called multiple times. Your application needs to be able to respond accordingly.