1

one simple question, and one harder:

1) can the sender ID (Gmail account) be different from the one we need to add on the phone under Settings-->Account?

2) I have to add an account automatically (coding..), and I'm trying to solve it but is it possible to hide the mail of the account I want to add under Settings-->Account? I don't want the people know the email address.

Thanks.

psk
  • 121
  • 1
  • 12
  • For 1st it could be different.what you use in your C2dm registration from the phone under Settings-->Account. – deepak Sharma Feb 06 '12 at 15:35
  • so can I use mail1@gmail.com as sender ID and mail2@gmail.com under Settings-->Account? What it seems to me is that it's important just to have a gmail account on the phone, even previously added: am I right? – psk Feb 06 '12 at 15:57
  • the sender id you use when you register for push notifications on the phone should most definitely be different than the signed-in google account on the phone. why would you ever need to covertly add an account on the phone? – hankystyles Feb 06 '12 at 17:03
  • I will let you understand how my app should work. When the app is installed, I have to be sure there's a Google account on the phone, otherwise the c2dm won't work. Since I count a lot of app downloaded, I was thinking to add by code a Gmail account, to prevent the situation of a not-working app, instead of explicitly asking to add a Gmail account (you know, better user-experience). The problem is that in this way several users can synchronize the email I provide: also, thay can spam on it, and some users will have notifications about all this.. is it clear? – psk Feb 06 '12 at 17:16
  • I'd definitely recommend against that. There's all kinds of security implications inherent in that approach. The way I see it you can either accept that some people will not be able to use your app due to restrictions inherited from c2dm, or try to roll your own notification system so you don't have to worry about piggybacking on the signed in google account like c2dm does. – hankystyles Feb 06 '12 at 21:49
  • yeah, you are right.. but still I have to find a solution to have more users as possible.thanks! – psk Feb 07 '12 at 19:00

2 Answers2

1

The GMail account on the phone is used internally to identify the recipient of the C2DM message. First a client registers itself, then (when a C2DM message is sent) all registered clients receive the C2DM message. More than one client can register them self as recipent for a C2DM message.

From the Google C2DM site (see Registering):

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", emailOfSender);
startService(registrationIntent);

The parameter app identifies the package name used by the registration process aside with the sender ID (in the code above the var emailOfSender). You see that the GMail account on the device is not used in the code, but will be used internally to identify the mobile device on the C2DM server (either the Android implementation provides the client side GMail account directly or an ID linked to the GMail account).

Google says: It requires devices running Android 2.2 or higher that also have the Market application installed. This is because the Market app maintains the connection to the C2DM server. The registration ID is different for all devices. Prior for sending C2DM messages from your server the client has to tell the server the registration ID.

When you want to create an application for sending C2DM messages (on the server side), you need also an GMail account (the SenderID we used on the device). Typically the pattern "one GMail account per application" is used. When you register for C2DM you have to enter the SenderID and the namespace of the receiving Android app into the registration form - exactly the same information as used on the client to register the device.

Both GMail accounts are not public. The relationship is n-1-m, which means n clients and m server are registering them self at one C2DM server. Only Google (the C2DM server) knows which GMail accounts are used.

I have one real life GMail address which is used on my mobile. I have on debugging GMail address which I use on my emulator. Then I have 3 GMail accounts for every C2DM capable application I wrote.

ChrLipp
  • 15,526
  • 10
  • 75
  • 107
  • So you say that when I have to retrieve the registrationId I have to specify the sender ID (the one I previously specified in the form to access the c2dm) and the (or one of the ) gmail account used on the phone? – psk Feb 07 '12 at 19:42
  • I updated the answer above and inserted the code for registration on the client. The answer is no - you use only the SenderId. Internally (in the Android C2DM code) each client has to be identified and I assume that for this the gmail account on the phone is used but you do not use it in any SDK function and it will not be published to any sender. – ChrLipp Feb 08 '12 at 12:10
  • Damn, I'm getting crazy: how then the C2DM is going to recognize the phone? in the registration phase, you say that for each app I have to specify just the Sender ID in the "emailOfSender" field (not with the Gmail account that is on the phone). The Registration ID is connected just to this info, then (I guess) it "should" be the same for each phone, isn't it? Or will the registration ID be different for each device is requesting it? – psk Feb 08 '12 at 18:26
  • Edited the text. The registration ID is different on each device. C2DM is not a broadcast, it is a point to point messaging service. Even when you don't use the GMail account on the phone in the API this doesn't mean that it is not used. The market app performs the registration and this app knows your account data pretty good. – ChrLipp Feb 09 '12 at 10:03
0

Sorry, if my question is a little bit (or even a lot) stupid, but as I understood:

registrationIntent.putExtra("sender", emailOfSender);

instead of emailOfSender I should put some real email address for C2DM needs, but should this email be different for each app installed on different device, I mean should I take this email somewhere from device settings, or I can hardcode it?

I was repeating tutorial from http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html and noticed:

// Sender currently not used
intent.putExtra("sender", "nonsenses@gmail.com");

So I left it like that, after it while developing server test part I put:

public class SecureStorage {
    public static final String USER = "your_registeredUser";
    public static final String PASSWORD = "your_password";
}

real credential here, and when I was trying to send message to application I received response 200 but no messages on device, as soon as I changed nonsenses@gmail.com to email account used in server side application - I received a notification at once.

Artem Svystun
  • 179
  • 1
  • 14
  • 1
    There are no stupid questions. emailOfSender must be the one you have signed up for the C2DM. And it is unique for each app installed on different devices. Regarding the notifications not received, even though you got the 200 response code, I read that it depends by two factors: first, the emulator (it might work better on the device); second, the C2DM is a best effort service, so it may loose some data.. – psk Jun 20 '12 at 07:13