NickT
NickT

Reputation: 23873

GCM, user notifications, two GCM aware apps on the same device, which one is triggered when GCM message sent with notification key?

I think I understood the rationale behind the new notification_key feature of GCM as being 'just send the message to the user and only make them read it once'. I inferred it from this section of the docs:

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.

Until very recently I had two GCM apps that I wrote residing on my phone. One had the old deprecated method of implementing GCM, the other used the new API. Naturally they had different registration ids.

If I reinstate the old app and request a notification key and send those two differing reg ids in the request, then when I sent a GCM using the notification key, which app's IntentService would be triggered?

Upvotes: 1

Views: 842

Answers (1)

Eran
Eran

Reputation: 394146

If you use a different Google API project ID and API Key for each app, you'll be able to add only registration IDs of one of the application to the notification key, since you specify the project ID and API key in all user notification related requests:

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"

In this case only one of the apps will get the message (since the other registration ID won't be valid for your notification key).

If you use the same project ID for both apps, it would indeed be interesting to see which application gets the message. You could probably force the message to be delivered only to one of the apps by using the restricted_package_name parameter when sending the message:

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.

Upvotes: 1

Related Questions