简体   繁体   中英

Google Cloud Messaging send notification to all devices

I'm new in GCM. I would like to send an message to all devices that have the app installed. I read about registration_id: after the first connection to GCM, google send this unique string to device. I'm a beginner in server world but if I'm not mistaken, in server side, for sending a notification to devices I have to send array of registration_id and the message to google.

Google knows how has the registration id? Is there a way to send messages to all devices without pass the registrarions id? Thank you.

With GCM 3.0 it's now possible to send a notification to all devices thanks to topics support. The app must suscribe to one or more topics and the server can send notifications to that topic without specifying individual devices.

https://developers.google.com/cloud-messaging/topic-messaging

You can suscribe all devices to a topic called "global" and then send the message to "/topics/global" instead of sending them to all the registration_ids.

Is there a way to send messages to all devices without pass the registrarions id?

No way.
After successfully registering on GCM, you (the Android application) should send the registration id to your application server and store them somewhere, in a database for example. This registration id will be used to send a notification to a particular device.

To send a notification to all devices, would mean then to select all the registration ids from that database, and as you said, put them in an array and pass them further to GCM.

Update: With Firebase Cloud Messaging, it is now possible to use https://firebase.google.com/docs/cloud-messaging/android/topic-messaging to send notifications without explicitly specifying registration IDs.

您需要发送设备的reg id列表,并且此列表不应超过1000这是GCM的限制,如果您要向1000多个设备发送消息,那么您需要以1000块的形式打破列表。

YES, there is a way to send a message to all!

Just send in the 'to' field the '/topics/global' value, rather then in the 'registration_ids' field the ids.

For example in php:

'to' => "/topics/global",

and not this:

'registration_ids'  => $this->devices

Create the notification_key , which identifies the device group by mapping a particular group to all of the group's associated registration tokens(You can create notification keys on the app server). With a notification_key , instead of sending one message to one registration token at a time, the app server can send one message to the notification_key , and GCM then sends the message to all of the group's registration tokens.

Also note that maximum number of members allowed for a notification_key is 20 .

Google Dev site has added a new guide for this topic in particular. https://developers.google.com/cloud-messaging/notifications#sending_downstream_messages_to_device_group

I think there is a confusion here. I had used the github sample code (app server in Java deployed to Tomcat for example) and Android app. There, I didn't "pass" or "send" any registration Id to the app server. It called the relevant APIs to retrieve the registration IDs and use them to send notifications. Why is every thread about GCM registration ID saying that one needs to pass registration IDs to 3rd party app server? I am afraid I don't agree. I think 3rd Party app server can query GCM server itself to find out which devices have registered to receive notification from a particular sender (sender id). Having to manually pass the registration IDs to 3rd party app server defeats the whole purpose of automating the process. Maybe I am missing something here or I am using the deprecated content. Anyway, how can an automated process involve manual intervention once it starts?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM