GCM Android,推送通知未被接收

3
我正在开发一款Android应用程序,将从GCM服务器接收推送通知。我使用PHP作为第三方服务器。
我有几个问题。
  1. When I send request to gcm server from my php script it gives me the following response

     {"multicast_id":8799227316277290616,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1341388064110557%5d17b789f9fd7ecd"}]}
    

    Now the response seems fine but you can see a % sign in the message_id. Is that ok? if it's not than how am I able to recieve the correct message_ID?

  2. When I use json_decode in my php script and echo this multicastid it gives me something like this

    8.7992273162773E+18
    

    and I am sure it will give the same type of value when I'll echo message_id also. So why it is not echoing the correct value?

  3. My last question is that when I send this request which seems right and open my android application there is no notification there. Is it caused by the above errors or there is some other problem?


我收到的响应是 {"multicast_id":8544536079568251693,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1349952207538943%87d780faf9fd7ecd"}]},但消息没有发布到设备上。可能出了什么问题? - Ramaraju.d
你可能无法正确地在设备中接收值。请检查从服务器发送和在设备中接收的参数名称。 - Mj1992
嗨Mj,我检查了参数,它们没问题,但是问题仍然存在。 - Ramaraju.d
我建议您将其作为另一个问题发布。希望更多的人能够看到并帮助您更快地解决问题。 - Mj1992
是的,我明白了。非常感谢。 - Ramaraju.d
2个回答

3

我在使用C2DM时遇到了类似的问题。原因是我请求配额时所用的Android应用程序名称与实际不一致。一旦更正了包名称,问题就解决了。


抱歉,我不明白你实际上在建议什么。我正在模拟器上运行程序,所以它能在模拟器上工作吗?而且我没有理解你关于应用程序名称匹配的说法。 - Mj1992
模拟器必须安装有Android市场,因此您可能需要下载特殊的AVD...默认的可能无法正常工作。此外,Android应用程序的软件包名称必须与您在Google注册时使用的相同。 - Amol Gupta
我在模拟器上没有安装 Android Market,我需要购买 Android Marketplace 账户吗?还是 Google 免费提供(特殊 AVD)?当我注册 Android GCM API 时,Google 没有要求我输入应用程序包名称。你说的是市场注册吗?因为我还没有注册市场。 - Mj1992
GCM中不再需要注册包名,而在C2DM中是必须的。很抱歉指出这一点,是我的错。现在没有官方带有市场/Play安装的AVD。您只能在设备上测试推送,否则您可以通过几次谷歌搜索找到一些带有市场的破解版AVD。 - Amol Gupta
1
你可能想要查看android.amolgupta.in/2012/07/google-cloud-messaging-gcm-tutorial.html,了解完整的GCM实现和代码。 - Amol Gupta
显示剩余3条评论

0
在我的情况下,安卓应用程序没有运行,因此无法接收推送通知。我启动了应用程序,然后就能够接收消息了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接