GCM注册ID改变GCM、ID

2023-09-12 08:07:29 作者:请叫我霸气哥

我开发了用GCM技术的应用程序,一切正常。

I developed an application which used GCM technology and everything is OK.

我观察到的一段时间后,设备会改变注册ID,这已经引起了我的应用程序问题,因为我的应用程序取决于注册ID。

I observed that the registration ID of the device changes after a period of time and this has caused a problem in my app because my app is dependent on the Reg ID.

所以,我怎样才能得到一个固定的注册ID的客户呢?

So how I can get a fixed Reg ID for clients?

推荐答案

我读了2个原因在在这里,当你GCM注册ID可能会改变:

您需要在每次更新重新注册每个设备的 应用程序。 您还将需要重新注册设备,如果安卓的版本,它的运行已经更新 You’ll need to re-register every device each time you update your app. You’ll also need to re-register a device if the version of Android it’s running has been updated

PS:以下旧答案的参考已经从谷歌的网页被删除,所以可能不再有效

如果你看到标题下的第二个点启用GCM在架构概述页,它说:

If you see the second point under the heading Enable GCM on Architectural Overview page, it says:

请注意,谷歌可能会定期刷新注册ID,所以你   应该设计自己的Andr​​oid应用程序的理解是,   com.google.android.c2dm.intent.REGISTRATION意图可被称为   多次。 Android应用程序需要能够应对   因此,

Note that Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times. Your Android application needs to be able to respond accordingly.

所以,处理,你应该有一个广播监听器它可以处理 com.google.android.c2dm.intent.REGISTRATION 的意图,这谷歌发送到应用程序时,它刷新注册ID。广播接收机将有的onReceive 法的意图。从意向即可获得捆绑使用,你可以提取谷歌新注册ID。您可以保存并将其发送给第三部分的服务器来替换你的previous注册ID的用户。

So, for handling that you should have a Broadcast Listener which could handle com.google.android.c2dm.intent.REGISTRATION intent, which Google send to the app when it has to refresh the registration ID. The broadcast receiver will have the onReceive method with an Intent. From the intent you can get the Bundle using which you can extract the new registration ID from Google. You can save that and send it to the 3rd part server to replace your previous registered ID for that user.

此外,您可能会看到这对这个问题回答In GoogleCloudMessaging API,如何处理注册ID的更新或过期的?。

Also you may see this answer on the question In GoogleCloudMessaging API, how to handle the renewal or expiration of registration ID?.

论Should应用程序调用gcm.register()每七天,以确保有效的注册证书?的问题也可能是一些使用。

Discussion on Should applications call gcm.register() every seven days to ensure valid registration IDs? question might also be of some use.

希望这有助于你了解如何处理它。

Hope this helps you understand how to handle it.