Android GCM 是如何工作的?
How Android GCM works?
我想知道 android 推送框架如何能够区分通过 GCM 接收的数据并将其转发到它预期的适当 android 应用程序?
谁能告诉我这是怎么做到的?
GCM 代表 Google 云消息传递。
在任何 Android 设备上收到的每个推送通知仅由 GCM 发送。
发件人 -> GCM -> Android 设备
当发件人发送推送通知时,它会转到 GCM。 GCM 通过其唯一设备 ID 接收推送并将其转发到特定的 Android 设备。
GCM 无法在没有唯一设备 ID 的情况下传送推送。
在实现推送通知时,有两个重要的事情,应用程序密钥和服务器密钥......这些是唯一的密钥.. 使用这些密钥 GCM 识别与推送通知相关的应用程序
您的问题:android 推送框架如何能够区分通过 GCM 收到的数据并将其转发到适当的 android 应用程序。
From your question it looks like you willing to know about data
workflow & Client Server architecture that exists in applications
which are using the GCM service.
根据 google 的文档“Google Cloud Messaging for Android (GCM) 是一项帮助开发人员将数据从服务器发送到他们的 Android 应用程序的服务在 Android 设备上”。 GCM 是 Google 为开发人员提供的一项服务,可帮助开发人员将数据从服务器发送到任意数量的 Android 设备。
简化的特定于应用程序的工作流程:
The push notification can be broadcasted either to the mass audience
or a select set of users. Mass audience is targeted when the
notification has to be sent about a marketing campaign. A subset of
users are targeted when a personalized information has to be sent.
以下步骤解释了推送通知如何在 android 设备上工作:
- 首先android设备发送发件人ID,应用程序ID到GCM服务器
注册。
- 注册成功后,GCM 服务器会向 android 设备发出注册 ID。
- 收到注册id后,设备会将注册id发送给我们的服务器。
- 我们的服务器会将注册 ID 存储在数据库中以供进一步使用。
- 每当需要推送通知时,我们的服务器都会向 GCM 服务器发送一条消息以及设备注册 ID(即
较早地存储在数据库中)。
- GCM 服务器将使用设备注册 ID 将该消息传送到相关移动设备。
这个也可以用下图来理解
示例工作流:
So, from above images it easy to understand that whenever the android
application is first installed by the user, then it registers itself
to GCM server, and obtains unique GCM ID, then it's our Host servers
responsibility to keep this newly registered Registration ID of the
android user into Database, and then it will be used whenever server
side application willing to send the message to that particular
android user.
所以,让我们考虑一个案例;假设一个服务器想要发送一些数据给 Android 用户,它在第一次安装时已经注册了它的 GCM ID 1234567,并且因为它在服务器的数据库中,服务器应用程序将从数据库中获取它,并简单地以 JSON 格式向 GCM 服务器发出 HTTP POST 请求,这将注册用户的 GCM ID 以及要发送的数据, GCM 服务器以同样的方式记录了所有已注册的 GCM/Android 客户端,它直接将该消息转发给预期的 android 用户,并且 android 应用程序在用户的 phone 将引发通知警报,以指示推送通知已到达。
希望这能回答问题!
我想知道 android 推送框架如何能够区分通过 GCM 接收的数据并将其转发到它预期的适当 android 应用程序?
谁能告诉我这是怎么做到的?
GCM 代表 Google 云消息传递。 在任何 Android 设备上收到的每个推送通知仅由 GCM 发送。
发件人 -> GCM -> Android 设备
当发件人发送推送通知时,它会转到 GCM。 GCM 通过其唯一设备 ID 接收推送并将其转发到特定的 Android 设备。
GCM 无法在没有唯一设备 ID 的情况下传送推送。
在实现推送通知时,有两个重要的事情,应用程序密钥和服务器密钥......这些是唯一的密钥.. 使用这些密钥 GCM 识别与推送通知相关的应用程序
您的问题:android 推送框架如何能够区分通过 GCM 收到的数据并将其转发到适当的 android 应用程序。
From your question it looks like you willing to know about data workflow & Client Server architecture that exists in applications which are using the GCM service.
根据 google 的文档“Google Cloud Messaging for Android (GCM) 是一项帮助开发人员将数据从服务器发送到他们的 Android 应用程序的服务在 Android 设备上”。 GCM 是 Google 为开发人员提供的一项服务,可帮助开发人员将数据从服务器发送到任意数量的 Android 设备。
简化的特定于应用程序的工作流程:
The push notification can be broadcasted either to the mass audience or a select set of users. Mass audience is targeted when the notification has to be sent about a marketing campaign. A subset of users are targeted when a personalized information has to be sent.
以下步骤解释了推送通知如何在 android 设备上工作:
- 首先android设备发送发件人ID,应用程序ID到GCM服务器
注册。
- 注册成功后,GCM 服务器会向 android 设备发出注册 ID。
- 收到注册id后,设备会将注册id发送给我们的服务器。
- 我们的服务器会将注册 ID 存储在数据库中以供进一步使用。
- 每当需要推送通知时,我们的服务器都会向 GCM 服务器发送一条消息以及设备注册 ID(即 较早地存储在数据库中)。
- GCM 服务器将使用设备注册 ID 将该消息传送到相关移动设备。
这个也可以用下图来理解
示例工作流:
So, from above images it easy to understand that whenever the android application is first installed by the user, then it registers itself to GCM server, and obtains unique GCM ID, then it's our Host servers responsibility to keep this newly registered Registration ID of the android user into Database, and then it will be used whenever server side application willing to send the message to that particular android user.
所以,让我们考虑一个案例;假设一个服务器想要发送一些数据给 Android 用户,它在第一次安装时已经注册了它的 GCM ID 1234567,并且因为它在服务器的数据库中,服务器应用程序将从数据库中获取它,并简单地以 JSON 格式向 GCM 服务器发出 HTTP POST 请求,这将注册用户的 GCM ID 以及要发送的数据, GCM 服务器以同样的方式记录了所有已注册的 GCM/Android 客户端,它直接将该消息转发给预期的 android 用户,并且 android 应用程序在用户的 phone 将引发通知警报,以指示推送通知已到达。
希望这能回答问题!