Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

android - Emails in C2DM?

I have developed push notification system in android using c2dm, It's working fine but I having one problem i-e it works fine with one email only.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems that you are under the wrong impression that the Role Email account which is created to identify the application using the C2DM service should be changed in the registration intent.

You must have that role email the same as the one on the server otherwise Google will not be able to identify your application as sender/receiver of this c2dm message. Sample Registration Intent:

    Intent registrationIntent = new Intent(
            C2DMessaging.REQUEST_REGISTRATION_INTENT);
    registrationIntent.setPackage(C2DMessaging.GSF_PACKAGE);
    registrationIntent.putExtra(
            C2DMessaging.EXTRA_APPLICATION_PENDING_INTENT,
            PendingIntent.getBroadcast(context, 0, new Intent(), 0));
    registrationIntent.putExtra(C2DMessaging.EXTRA_SENDER, senderId);
    context.startService(registrationIntent);

The Variable senderId here should hold the role account you created and signed up for C2DM on the google C2DM signup Page

This same email is used to obtain the Authentication token from google servers which is used to send C2DM messages later

Sample server code to get an authentication key:

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("Email",
                senderId));
        nameValuePairs.add(new BasicNameValuePair("Passwd", "testpassword"));
        nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE"));
        nameValuePairs.add(new BasicNameValuePair("source",
                "Fleet Tracker Pro"));
        nameValuePairs.add(new BasicNameValuePair("service", "ac2dm"));
        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(
                response.getEntity().getContent()));

        String line = "";
        while ((line = rd.readLine()) != null) {
            if (line.startsWith("Auth=")) {
                String auth = line.substring(5);
                System.out.println("Auth token = " + auth);
                return auth;
            }
        }

notice the variable senderId this should also hold the role account you created and signed up for C2DM on the google C2DM signup Page any other email can be changed to whatever you like, but these to emails have to remain identical

here is the definition from google C2DM page at google code:

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, [email protected].

I hope i helped have a nice day.

would have been nice if you included code snippets or more information about the emails you are talking about.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...