asp.net - Sending Push Notification to multiple android devices using asp .net -
i'm trying send push notifications multiple android devices.
for 1 device working, when tried add multiple device registrationids not; gcm returns error=invalidregistration
var message = tmessage.text; //message text box var title = ttitle.text; string stringregids = null; list<string> regids = new list<string>(); regids.add(redidemulnew); regids.add(regidmobilenew); stringregids = string.join("\",\"", regids); webrequest trequest; trequest = webrequest.create("https://android.googleapis.com/gcm/send"); trequest.method = "post"; trequest.contenttype = " application/x-www-form-urlencoded;charset=utf-8"; trequest.headers.add(string.format("authorization: key={0}", applicationid)); trequest.headers.add(string.format("sender: id={0}", sender_id)); string postdata = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + message + "&data.title=" + title + "®istration_id=" + stringregids + ""; byte[] bytearray = encoding.utf8.getbytes(postdata); trequest.contentlength = bytearray.length; stream datastream = trequest.getrequeststream(); datastream.write(bytearray, 0, bytearray.length); datastream.close(); webresponse tresponse = trequest.getresponse(); datastream = tresponse.getresponsestream(); streamreader treader = new streamreader(datastream); string sresponsefromserver = treader.readtoend(); //get response gcm server. lbresponse.text = sresponsefromserver; //assigning gcm response label text treader.close(); datastream.close(); tresponse.close();
i suspect below code has issue:
string stringregids = null; list<string> regids = new list<string>(); regids.add(redidemulnew); regids.add(regidmobilenew); stringregids = string.join("\",\"", regids);
both device registration ids valid, have checked push notifications individually.
thanks
after searching long time found "multicast messages (sending more 1 registration ids) allowed using http json format only"
here reference https://developers.google.com/cloud-messaging/server-ref#table1
and example http://labs.distriqt.com/post/1223
string postdata = "{ \"registration_ids\": [ \"" + stringregids + "\" ], " + "\"data\": {\"title\":\"" + title + "\", " + "\"message\": \"" + message + "\"}}";
Comments
Post a Comment