Android c2dm 邮箱地址问题

发布于 2024-11-24 13:53:37 字数 132 浏览 1 评论 0原文

我正在使用 C2DM 开发 Android 推送通知应用程序,我在应用程序中遇到了一些问题。 当我在即服务器和客户端应用程序上使用相同的电子邮件地址时,该应用程序正在工作,

任何人都可以告诉我会出现什么问题。

阿尔塔夫

I am developing android push notification application using C2DM,I am facing some problems in my application.
The application is working when I am using same email address on both i-e server and client applications,

Can anyone tell me what will be the problem.

Altaf

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走干脆点 2024-12-01 13:53:37

您似乎有一个错误的印象,即应该在注册意图中更改为识别使用 C2DM 服务的应用程序而创建的角色电子邮件帐户。

您的角色电子邮件必须与服务器上的电子邮件相同,否则 Google 将无法将您的应用程序识别为此 c2dm 消息的发送者/接收者。
示例注册意图:

    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);

此处的变量 senderId 应保存您在 google C2DM 注册页面

这同一封电子邮件用于从 google 服务器获取身份验证令牌,该令牌用于稍后发送 C2DM 消息 用于

获取身份验证密钥的示例服务器代码:

        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;
            }
        }

注意变量 senderId,这也应该具有该角色您在 Google C2DM 注册页面上创建并注册 C2DM 的帐户
任何其他电子邮件都可以更改为您喜欢的任何内容,但这些电子邮件必须保持相同,

这里是 Google C2DM 页面(Google 代码):

发件人 ID 与应用程序关联的电子邮件帐户
开发商。发件人 ID 在注册过程中用于
识别允许发送消息的 Android 应用程序
设备。该 ID 通常是基于角色的,而不是基于角色的
个人帐户 - 例如,[电子邮件受保护]

我希望我能帮助你度过愉快的一天。

如果您包含代码片段或有关您正在谈论的电子邮件的更多信息,那就太好了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文