android – 连接到在本地服务器上运行的GCM服务器

我正在使用Google Cloud Messaging(GCM)处理推送通知.我可以在this tutorial之后设置服务器和客户端.

服务器在Apache Tomcat6.0(localhost)上运行,在Android API(API级别17)上运行Android模拟器.我有发件人ID和API密钥.从模拟器运行时,我获得了成功的设备连接消息.在此之后,从服务器发送消息后显示以下错误.

com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401()
com.google.android.gcm.server.Sender.sendnoretry(Sender.java:211)
com.google.android.gcm.server.Sender.send(Sender.java:125)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

从其他帖子,我理解错误的API密钥是罪魁祸首.但就我而言,我确保使用API​​控制台中正确的一个.

顺便说一句,当我运行模拟器时,我看到一条消息’将regId发送到服务器’.什么是注册ID?它与发件人ID不同;看起来像编码的.

有突破吗?

编辑

问题终于解决了! Ant没有正确构建WAR文件.因此API密钥几乎​​不会更新.发现这个虫子真是一场噩梦.谢谢大家的投入!

最佳答案
我建议你阅读GCM指南:

GCM guide for Android

发件人ID是一个常量,将用于GCM和服务器之间的通信.当您的手机注册其服务时,regsitratiomID(regID)由GCM服务管理.

一个更好的定义:
http://developer.android.com/google/gcm/gcm.html

发件人ID:

A project number you acquire from the API console,as described in Getting Started. The sender ID is used in the registration process to identify an Android application that is permitted to send messages to the device.

注册ID:

An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID,it sends it to the 3rd-party application server,which uses it to identify each device that has registered to receive messages for a given Android application. In other words,a registration ID is tied to a particular Android application running on a particular device.

相关文章

Android 通过adb shell命令查看内存,CPU,启动时间,电量等...
Monkey Android app稳定性测试工具之Monkey使用教程 by:授客...
Android 常见adb命令 by:授客 QQ:1033553122 1、 查看所有已...
这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...