Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 597
Tenaciousd93 Avatar asked Jul 31 '13 08:07

Tenaciousd93


4 Answers

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.

like image 78
Daniel Rodríguez Herrera Avatar answered Nov 01 '22 17:11

Daniel Rodríguez Herrera


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.

like image 27
Andy Res Avatar answered Nov 01 '22 16:11

Andy Res


You need to send the list of reg id of devices and also this list should not exceed 1000 this is a limitation of GCM if you want to send message to more than 1000 devices then you need to break the list in chunks of 1000.

like image 6
Sumit Dhaniya Avatar answered Nov 01 '22 16:11

Sumit Dhaniya


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
like image 6
Mark Szabo Avatar answered Nov 01 '22 17:11

Mark Szabo