Android 什么是 GCM 注册 ID?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25526042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is GCM Registration ID?
提问by sipdorus
Hello I want to add gcm to my application. My application is a news application. User can view news after registration. Application asks user interests (economy, sports, cars etc.) and saves them. I want to send news to user as notification from php and mysql. I must decide to send which news to which users. So i need registration ids.
您好,我想将 gcm 添加到我的应用程序中。我的应用程序是一个新闻应用程序。用户注册后可以查看新闻。应用程序询问用户兴趣(经济、运动、汽车等)并保存它们。我想将新闻作为来自 php 和 mysql 的通知发送给用户。我必须决定向哪些用户发送哪些新闻。所以我需要注册ID。
Is it android device number?
Or a combination of Android device google account and android device number?
Or a combination of Android device google account and android device number and My application user id?
是安卓设备号吗?还是安卓设备谷歌账号和安卓设备号的组合?
还是 Android 设备 google 帐户和 android 设备号和我的应用程序用户 ID 的组合?
Example
例子
Android device id = a => GCM RegID=a
Android device id = a , google account id=b => GCM RegID=ab
Android device id = a , google account id=b, application x user id=c => GCM RegID=abc
Android device id = a => GCM RegID=a
Android device id = a , google account id=b => GCM RegID=ab
Android device id = a , google account id=b, application x user id=c => GCM RegID =abc
If x user logs out from application and y user login in same device will GCM RegId change? If it does not change and i push economy news to y user (who does not interest about economy) device will show wrong notification to wrong user. So what is GCM registration id?
如果 x 用户从应用程序注销,而 y 用户在同一设备上登录,GCM RegId 会改变吗?如果它没有改变并且我将经济新闻推送给 y 用户(对经济不感兴趣)设备将向错误的用户显示错误的通知。那么什么是 GCM 注册 ID?
回答by Eran
A Registration ID is an identifier assigned by GCM to a single instance of a single application installed on an Android device. The device is assigned this identifier when it registers to Google Cloud Messaging. The GCM documentation doesn't specify what information is encoded in this identifier.
注册 ID 是 GCM 分配给安装在 Android 设备上的单个应用程序的单个实例的标识符。设备在注册到 Google Cloud Messaging 时会被分配此标识符。GCM 文档未指定此标识符中编码的信息。
In some older Android versions (pre-4.0.4), a Google account is required to register to GCM.
在一些较旧的 Android 版本(4.0.4 之前)中,需要 Google 帐户才能注册到 GCM。
If multiple users use the same app on the same device, they will be have the same registration ID, since GCM doesn't care about which user logs-in to the app. It's up to your server to determine which user is currently logged in to your app in a certain device, and based on that knowledge to deliver only relevant GCM messages to that device.
如果多个用户在同一设备上使用同一个应用程序,他们将拥有相同的注册 ID,因为 GCM 不关心哪个用户登录到应用程序。由您的服务器确定当前在某个设备上登录到您的应用程序的用户,并根据该知识仅向该设备传送相关的 GCM 消息。
回答by Pankaj Kumar
Registration id is a unique identifier for particular package on a particular device. GCM identifies the target using this id.
注册 ID 是特定设备上特定包的唯一标识符。GCM 使用此 ID 识别目标。
In your case this id is not going to solve your problem.
在您的情况下,此 ID 不会解决您的问题。
Case 1:
情况1:
If you unregister device from GCM on logout, and register again, this is not guaranty that registration id will be different (may be and may not be).
如果您在注销时从 GCM 取消注册设备,然后重新注册,这并不能保证注册 ID 会有所不同(可能是也可能不是)。
Case 2:
案例2:
GCM refreshes registration id time to time.
GCM 会不时刷新注册 ID。
So this id is not going to a solution to identify logged user.
所以这个 id 不是用来识别登录用户的解决方案。
Possible solution
可能的解决方案
Send only generic message from GCM to device, like "hey you have something new, go to server". Now device will request to server for new item. Here server will identify the logged user and give him the respective data.
仅从 GCM 向设备发送通用消息,例如“嘿,您有新东西,转到服务器”。现在设备将向服务器请求新项目。这里服务器将识别登录的用户并向他提供相应的数据。