Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send GCM messages to multiple devices at a time

I want to send same message to multiple devices in android using GCM. Currently i am able to send push notification to my device as i am explicitly specifying my registration ID in PHP code. But i want to send it to multiple devices so how can i do this??? Any help or idea are highly appreciated.

Please guide for this Thanks

like image 900
xyz Avatar asked Nov 22 '12 10:11

xyz


1 Answers

What you should do is send multiple registrations Ids (up to 1000 at once) when you send your message to GCM, and you will need to use JSON as your request format.

You can read more about that here: https://developers.google.com/cloud-messaging/server-ref#downstream

You will need to add your list of Id's to the registration_ids field:

A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs. To send a multicast message, you must use JSON. For sending a single message to a single device, you could use a JSON object with just 1 registration id, or plain text (see below). Required.

Here is an example request from their docs:

Here is a message with a payload and 6 recipients:

{ "data": {
   "score": "5x1",
   "time": "15:10"
  },
  "registration_ids": ["4", "8", "15", "16", "23", "42"]
} 
like image 136
selsine Avatar answered Nov 13 '22 00:11

selsine