Emails in C2DM?

懵懂的女人 提交于 2020-01-07 09:54:06

问题


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.


回答1:


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, my-app@gmail.com.

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.



来源:https://stackoverflow.com/questions/6725570/emails-in-c2dm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!