Getting primary email for using C2DM in android - android

I want to use a C2DM which will allow my Java Server to send Data to Android phone. Since for
using C2DM each device need its gmail ID, my Question is that how can i get the default email
associated with the android phone and use this email in C2DM.
is it possible to use this email for using C2DM.. if yes then how should i get default email of android phone.

First of all you cannot get which email is associated with the device and secondly you dont need client email you only need a registered email for sending C2DM notification but the condition is that you must have gmail account logged in on android

I think you misunderstand. You do not send C2DM messages to an email address, you send to a RegistrationID that the C2DM library issued to a copy of your application registered on a device. The only email address you need is your sender.
For reference: C2DM documentation

You do not need the users email for C2DM. This email address you have to specify is an address of yours. Have a look at the chrome2phone source - it is a good example for C2DM http://code.google.com/p/chrometophone/source/browse/

Related

C2DM - Device and third party server email accounts query

Looking entirely from the user account perspective, are the following pointers to be followed for the C2DM push system to work?
Manually sign up on https://developers.google.com/android/c2dm/signup and provide package name of my android app. consider emailId given is: foo#gmail.com
Programmatically Register from my android app using a email id, foo#gmail.com
From the third party application server send push notifications. Generate the authentication token using foo#gmail.com and pass****word.
My question is, is it mandatory to provide the same emailId in all the above places?
yes Please go though the links
https://developers.google.com/android/c2dm/
Sender ID An email account associated with the application's developer. The sender ID is used in the registration process to identify a Android application that is permitted to send messages to the device. This ID is typically role-based rather than being a personal account—- for example, my-app#gmail.com.
http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
http://android-developers.blogspot.in/2010/05/android-cloud-to-device-messaging.html
http://www.abolkog.com/portal/java-programming/117-android-push-notifications

Android C2DM, Sender ID in the Push App

The Android C2DM push app that I have developed has the reference of my sender is (example: "sender#gmail.com") in the application side code.
Case 1:
When I install this app on a Android device, the device has a gmail id as "personalid#gmail.com" in Accounts and Sync settings.
App is registered successfully with C2DM but it does not receive any of the pushed messages.
Case2:
When I use the same sender id ("sender#gmail.com") in the Android device's Accounts and Sync. I receive all the messages that I push.
Why case 1 is failing and case 2 (sender id all through) is successful?
Please make sure that you have signed out from built in gtalk application of your phone, if you are not signed out from gtalk app, then it will create ambiguity in between gtalk and ur personal app for messaged pushed from google server so it can not send message to any app and give exception.
For detailed information of push notification , please check https://developers.google.com/android/c2dm/
best c2dm tutorialis ,http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
This is the way that C2DM works. It makes sense that it works in this way since it requires the email address for both the registration id and authentication token.
When sending a push message, your third party server uses the registration id built on (probably) "sender#gmail.com", and authentication token built on the same email. Google's server looks on your device and tries to find that specific email address account. You can have multiple accounts on the device, but at least one of them has to be the account used to register the device.
Why would Google ask for the email anyway if it wouldn't have mattered? It would have been much easier to use directly the device's unique id.

Getting a unique RegistrationID of a Android device to C2DM

To use C2DM for my application i registered new Gmail account with Google as a Sender account.
Now i am confused that how to get RegistrationID for my device and how to associate it with the Sender account. i want to install this application on multiple Andorid phones so do i need unique RegistrationID for each Android phone .
There are two sides to C2DM:
Your server stores registration IDs for the users. It requests n auth code from Google's servers (using ClientLogin) and then uses that auth code to send push messages.
Your Android app requests a registration ID from Google's servers. It is sent one over C2DM. It sends it to the server, to be stored there (so messages can be sent to it).
This tutorial describes it all in detail, with code:
http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
A registration ID is like the address on a postal envelope - it describes where a push message is to be sent, the destination. So yes, you need one for each device. Registration IDs are actually assigned to a specific app (name space) on a specific device.
If you have added the boiler plate C2DM code from http://code.google.com/android/c2dm/ ,when the app registers, it will recieve a registration id , which you have to save it in a database on your server. The registration id can change so you have to notify the server, every time it changes.
To get the registraton id use
C2DMessaging.register(this, "email id");

Do I need different Authentication Token for each user for sending message using C2DM?

I know there is unique registartionId get from users email address for sending message to his device, but also do i need to have different authenctication id for each user?
If I am right we just need registrationId to send message to user, where as AuthenticationId is static, which is use to send message to user with registration id.
but in my case, I got Authentication Token using my developer email address, and if send message to the same email address I receive message. and If I send message to another user using registration id received from his email address and using authentication token got from my developer account email address user didn't receive message.
and again if I use authentication token got from user's email address and password and using his registration id user receive message.
The authenticationToken confirms that you have a valid Google account and thus are in general allowed to send C2DM messages. The registrationToken is directly tied to a user's device and your application. It allows your application to use your authenticationToken to send a message to the user's device.
You need one authenticationToken to send messages to all devices for which you have registrationTokens. Note however, that you should pick up a new authenticationToken every time you start sending messages, as those can be changed by Google at random.
I recall reading that Google advises to use different mail accounts for sending and receiving.
To the best of my knowledge the Authentication token is generated against the c2dm gmail id and the gmail account configured on the device.
That may be the reason why the other user is not receiving messages using your registration id.
So the answer to your question is yes, you need to have different Authentication Token for different user for sending message using C2DM.
You're correct that the authentication token is static, it serves to authenticate the app to the C2DM service. The registration id serves to identify the user you are sending the message to.
Since you are using your developer email account, it might be that the authentication token is invalidated. Did you check that? You'd get a 401 error sending the message. You shouldn't be using or collecting authentication tokens from your users, that shouldn't even work.
Note that C2DM assumes you are using a server component for your app as described here: http://code.google.com/intl/nl/android/c2dm/index.html#arch.
If you are trying to send a message to the C2DM server from the device, you're doing it wrong.

C2DM Mobile Registration Phase

I am new to C2DM and would like to test. I have a question about mobile registration phrase. since we need to use Google mail account in order to get the registration ID from C2DM server, is it possible to use device UUID instead of gmail account?
please advise or correct me if I have any miss understanding.
Thanks
Alex
no you must use the google mail account you used to register. So it kinda becomes your api key for C2DM. That email address is also used in contacting the google server when sending the actual notifications as a trust indicator between you and google.
You better use a separate Gmail address, not your personal Gmail and also not your mobile UUID (Universally Unique IDentifier). You have to use this email address in two different locations. One is in your Android application and the other one in your third party server. This email ID is important in the registration process. Which means the mobile phone which runs our C2DM enable Android app with the C2DM server. The Google documentation explains very well about the mobile implementation side but less with the server implementation side :-(

Categories

Resources