谷歌Coud Mesaging(GCM)和registration_id到期,我怎么会知道? [英] Google Coud Mesaging (GCM) and registration_id expiry, how will I know?

查看:131
本文介绍了谷歌Coud Mesaging(GCM)和registration_id到期,我怎么会知道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把骨架客户端/服务器应用程序GCM接受,并从我粗略的服务器显示在我的Andr​​oid手机的消息。我说'骨架'和'粗糙和准备,因为我的应用程序的registration_id很难codeD插入服务器端,我捕捉到调试器时,我开始样品Android应用程序和注册应用程序/设备组合的GCM价值服务器。我正要开始工作提供了一个读/写机制,为双方访问服务器上的一个简单的数据库来存储reg_id /设备组合时,我开始思考:

I've put together a skeleton client/server GCM app that accepts and displays messages on my Android phone from my rough and ready server. I say 'skeleton 'and 'rough and ready' because my app's registration_id is hard coded into the server side as the value I captured in the debugger when I started the sample Android app and registered the app/device combination on the GCM server. I was about to start working on providing a read/write mechanism for the two sides to access a simple database on the server to store the reg_id/device combinations when I got to thinking:

我知道这reg_id可以在任何时间过期,因为谷歌说,它可以。这是从文档清楚如何检查id是犹若确定,这是一个很大的中频,我再次启动应用程序。但是,为什么要我,或任何其他用户,重新开始吗?该GCMIntentService,在清单登记坐在那里捡消息作为必需的,没有必要再以任何理由运行应用程序。因此,当ID到期,我就停止获取信息 - 服务器可能知道从返回code,但不能告诉我的应用程序 - 没有复苏,除非我再次运行应用程序,并通过了的onCreate()和presumably registerClient()的方法。

I know this reg_id can expire at any time, because Google say it can. It's clear from the docs how to check that the id is still OK IF, and it's a big IF, I start the app again. However, why should I, or any other user, start it again? The GCMIntentService, registered in the manifest is sitting there picking up messages as required and there's no need to run the app again for any reason. So when the id expires, I'll stop getting messages - the server might know from the return code, but won't be able to inform my app - no recovery unless I run the app again and go through its onCreate() and presumably registerClient() methods.

当ID到期所以会发生什么?我没有看到任何在IntentService上..方法将执行。谷歌将自己发送正常的消息,说这是即将到期?我是否需要写一个报警任务每天运行并检查身份证?

So what happens when the id expires? I don't see that any of the on.. methods in the IntentService will execute. Will Google themselves send a normal message saying it's about to expire? Do I need to write an alarm task to run daily and check the id?

推荐答案

根据 GCM

这是现有注册ID可能不再是在若干有效   场景,包括:

An existing registration ID may cease to be valid in a number of scenarios, including:

      
  • 如果应用程序手动注销通过发出一个com.google.android.c2dm.intent.UNREGISTER意图。
  •   
  • 如果该应用程序会自动注册的,它可以发生(但并不保证)如果用户卸载应用程序。如果注册ID到期。谷歌可能会决定刷新注册的ID。
  •   
  • 如果该应用程序已经更新,但新的版本没有配置为接收com.google.android.c2dm.intent.RECEIVE意图广播接收器。
  •   
  • If the application manually unregisters by issuing a com.google.android.c2dm.intent.UNREGISTER intent.
  • If the application is automatically unregistered, which can happen (but is not guaranteed) if the user uninstalls the application. If the registration ID expires. Google might decide to refresh registration IDs.
  • If the application is updated but the new version does not have a broadcast receiver configured to receive com.google.android.c2dm.intent.RECEIVE intents.

考虑到登记相关的应答必火 com.google.android.c2dm.intent.REGISTRATION 的意图。所以,你应该从GCM的注册消息的照顾。

Consider that registration related responses will fire"com.google.android.c2dm.intent.REGISTRATION" intent. So you should take care of Registration messages sent from GCM.

更新

GCM医生说:

如果注册ID到期。谷歌可能会决定刷新   注册的ID。对于所有这些情况下,您应该删除这   从第三方服务器注册ID和停止使用它来发送   消息。发生在错误code为NotRegistered。

If the registration ID expires. Google might decide to refresh registration IDs. For all these cases, you should remove this registration ID from the 3rd-party server and stop using it to send messages. Happens when error code is NotRegistered.

考虑到上述事实为真,那么您的服务器上,你应该处理过期的ID和设置对他们的标志在你的数据库,下一次你的Andr​​oid客户端检查服务器(最后你必须做定期检查)或你叫 isRegisteredOnServer 上GCMRegistrar类,并得到了一个的结果,你应该火意向登记,以获得一个新的ID。

Considering the above fact as the truth, then on the your server you should handle expired IDs and set a flag on them in your db, the next time your android client check your server(finally you must do a periodical check) or you call isRegisteredOnServer on GCMRegistrar class and got a false result, you should fire REGISTRATION intent in order to get a new ID.

这篇关于谷歌Coud Mesaging(GCM)和registration_id到期,我怎么会知道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆