android - 我应该生成特定于应用程序还是特定于用户的 android GCM 注册 ID?

标签 android google-cloud-messaging

我正在开发一款具有登录功能的应用程序。我只为每个应用程序生成一个 gcm 注册 ID。如果其他用户登录同一个应用程序,他将开始接收针对前一个用户的通知。 如何处理这种情况,以便每个用户都能收到针对他/她的通知? 我应该为每个用户生成 gcm reg id 吗? 处理这种情况的标准方法是什么?

最佳答案

您可以尝试以下操作:

  1. 当用户注销时,发送请求以删除您服务器上的 token ,并在您的应用程序上将其删除;
  2. 一旦用户注销,您只需在您的服务器上删除“用户 ID”与“GCM token ”(或注册 ID)的关联。当有人再次登录时,您会与该 token 建立新的关联。

GCM token 是特定于应用程序的,但您在服务器上建立的关联完全取决于您。

我怎么强调都不为过,GCM 生成的 token 是APP SPECIFIC。如果您的用户在多个设备上登录,您的服务器应该处理该问题,将 user ID 关联到多个 Registration ID token 。

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.

根据文档,您的服务器还应该:

Before you can write client apps that use GCM, you must have an application server that meets the following criteria:

  • Able to communicate with your client.
  • Able to send properly formatted requests to the GCM connection server.
  • Able to handle requests and resend them using exponential back-off.
  • Able to store the API key and client registration tokens.
  • Able to generate message IDs to uniquely identify each message it sends. Message IDs should be unique per sender ID.

编辑:您可以阅读有关 GCM 的更多信息 here .

如需进一步阅读,您还可以在 Device Group Messaging 上阅读更多内容.

您还可以下载一些代码示例 here .

关于android - 我应该生成特定于应用程序还是特定于用户的 android GCM 注册 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32761419/

相关文章:

android - 无需发送消息即可获取 GCM 规范注册 ID

google-chrome - 在 ASP.NET 中获取 manifest.json GCM 推送通知的未经授权 401

android - GCM : Send notifications only for the current user logged in application

android - android中的六角形imageview

Android Market - 销售付费升级(不是更新)

android - 我想从 Xamarin Android 应用打开应用设置页面

android - Android 上 GooglePlayServicesUtil 的 NoClassDefFoundError

iOS 谷歌云消息传递负载

android - 无法在 phonegap 中显示联系人数据图像

android - 线性布局在设计中可见但在运行时不可见?