psk
psk

Reputation: 121

C2DM - role sender account

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.

Upvotes: 1

Views: 780

Answers (2)

Artem Svystun
Artem Svystun

Reputation: 179

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", "[email protected]");

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 [email protected] to email account used in server side application - I received a notification at once.

Upvotes: 0

ChrLipp
ChrLipp

Reputation: 15678

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.

Upvotes: 1

Related Questions