9

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.

Tenaciousd93
  • 3,438
  • 4
  • 33
  • 56
  • You need to store the registration_id into a database. Please take a look in my solution: http://stackoverflow.com/questions/17998875/googlecloudmessaging-returning-invalidregistration – Joubert Vasconcelos Aug 01 '13 at 22:24

6 Answers6

15

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.

11

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.

Elad Nava
  • 7,746
  • 2
  • 41
  • 61
Andy Res
  • 15,963
  • 5
  • 60
  • 96
  • Ok, thank you very much for your promt answer.. I will make a db on my server and put the query result of all devices registration id in the request for the notifications. Thanks. – Tenaciousd93 Jul 31 '13 at 09:45
  • 2
    This is no longer the correct answer. Updates to the Android push infrastructure has made this answer outdated. – Anders Marzi Tornblad Jun 08 '16 at 08:06
6

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.

Sumit Dhaniya
  • 596
  • 6
  • 14
6

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
Mark Szabo
  • 8,515
  • 3
  • 18
  • 26
1

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 thenotification_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

Orest
  • 6,548
  • 10
  • 54
  • 84
onexf
  • 3,674
  • 3
  • 22
  • 36
-1

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?

Prasad
  • 349
  • 2
  • 6
  • I didn't use you example but, if I'm not mistaken, I use this configuration: `1. APP START: app registers the device on google server. 2. I send the "unique code" of device on my server's DB. 3. SERVER: If I will send a notification to some devices, I query this "unique codes" from the DB and I send these to google server. 4. Only selected devices recive notification.` You must provide an array of ID of devices to google server, so you must store these IDs into your server. – Tenaciousd93 Dec 23 '13 at 08:29