在 Android 中实现 C2DM 时处理退避
我正在其中一个应用程序中实现 C2DM。如果注册 C2DM 时出现错误,我们需要退后,然后重试。我想知道用户是否需要采用相同的注册意图,或者用户是否需要调用任何其他意图以进行重试。
以下是我在其中一个代码中看到的两个意图。但如果注册失败,重试实际上永远不会发生,并且我没有看到生成任何注册 ID。
com.google.android.c2dm.intent.REGISTER com.google.android.c2dm.intent.RETRY
http://www.vogella.de/文章/AndroidCloudToDeviceMessaging/article.html。这是应用程序中使用的代码。
请建议我们如何处理回退。
I am implementing C2DM in one of the application. In case there is an error while registering for C2DM we need to backoff and then try again. I want to whether the user needs to go with the same registration intent or is there any other intent that user needs to call for retry purpose.
Below are the two intents that I have seen in one of the code. But in case the registration fails the retry actually never occurs and I do not see any registration id being generated.
com.google.android.c2dm.intent.REGISTER
com.google.android.c2dm.intent.RETRY
http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html. This is the code that is being used in the app.
Please advice as to how do we need to handle the back off.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要设置闹钟,以便在退避一段时间后重试注册
您需要将 RETRY 意图过滤器添加到 manifest.html 中的接收器声明中,警报代码可能看起来像这样
C2DMessaging 是来自 Jumpnote 应用程序的一个类,可以在此处找到 http://code.google.com/p/jumpnote/source/checkout
更新
确保重试权限设置在您的清单文件,如我对您的评论的回复中所建议的。我的清单看起来像这样
另外 - 这很容易在模拟器上测试 - 只需断开您的电脑与互联网的连接,您将收到服务不可用异常的重试事件,直到您重新连接到互联网
You need to set an alarm to retry the registration after a back off period of time
You need to add the RETRY intent filter to the receiver declaration in the manifest.html and the alarm code could look something like this
C2DMessaging is a class from jumpnote app which can be found here http://code.google.com/p/jumpnote/source/checkout
UPDATE
Make sure the RETRY permission is set in your manifest file as suggested in my response to your comment. My manifest looks something like this
Also - This is easy to test on the emulator - Just disconnect your P.C. from the internet and you will get retry events for service not available exceptions until you re-connect to the internet