android - GCM,用户通知,同一设备上的两个 GCM 感知应用程序,当 GCM 消息与通知 key 一起发送时触发哪个应用程序?

标签 android push-notification google-cloud-messaging

我想我理解 GCM 的新 notification_key 功能背后的基本原理是“只需将消息发送给用户并且只让他们阅读一次”。我从文档的这一部分推断出来:

With user notifications, 3rd-party app servers can send a single message to multiple instance of an app running on devices owned by a single user. This feature is called user notifications. User notifications make it possible for every app instance that a user owns to reflect the latest messaging state. For example:

If a message has been handled on one device, the GCM message on the other devices are dismissed. For example, if a user has handled a calendar notification on one device, the notification will go away on the user's other devices.

If a message has not been delivered yet to a device and but it has been handled, the GCM server removes it from the unsent queue for the other devices.

Likewise, a device can send messages to the notification_key, which is the token that GCM uses to fan out notifications to all devices whose registration IDs are associated with the key.

直到最近,我的手机上还有我编写的两个 GCM 应用程序。一个使用旧的已弃用的方法来实现 GCM,另一个使用新的 API。当然,他们有不同的注册 ID。

如果我恢复旧应用程序并请求通知 key 并在请求中发送这两个不同的注册 ID,那么当我使用通知 key 发送 GCM 时,将触发哪个应用程序的 IntentService?

最佳答案

如果您为每个应用程序使用不同的 Google API 项目 ID 和 API key ,您将只能将其中一个应用程序的注册 ID 添加到通知 key ,因为您在所有应用程序中都指定了项目 ID 和 API key 用户通知相关请求:

Here is the HTTP request header you should use for all create/add/remove operations:

content-type: "application/json"
Header : "project_id": <projectID>
Header: "Authorization", "key=API_KEY"

在这种情况下,只有一个应用程序会收到消息(因为另一个注册 ID 对您的通知 key 无效)。

如果您对两个应用程序使用相同的项目 ID,那么查看哪个应用程序收到消息确实很有趣。当 sending the message 时,您可以通过使用 restricted_pa​​ckage_name 参数强制将消息仅传送到其中一个应用程序。 :

restricted_package_name A string containing the package name of your application. When set, messages will only be sent to registration IDs that match the package name. Optional.

关于android - GCM,用户通知,同一设备上的两个 GCM 感知应用程序,当 GCM 消息与通知 key 一起发送时触发哪个应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22045325/

相关文章:

ios - 通过应用程序捕获推送通知

android - 轮询与推送 - 有什么理由避免推送通知?

android - 如何获取GCM API Key,菜单中没有已注册的应用程序

android - 在哪里检查 android fragment 中的方向变化

android - cordova 3.3 中的用户推送通知

push-notification - Actions on Google - C# 中的推送通知

java - 将我现有的服务器连接到 GCM

android - 三星S4支持BLE应用吗?

android - 随机 android.content.res.Resources$NotFoundException

android - 如何将uiview添加到cocos2d android