Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
public string SendNotification(string deviceId, string message)
{
    string GoogleAppID = "*************************************";
    var SENDER_ID = "******************";
    var value = message;
    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}", GoogleAppID));
    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=" + value + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + deviceId + "";
    Console.WriteLine(postData);
    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();
    tReader.Close();
    dataStream.Close();
    tResponse.Close();
    return sResponseFromServer;
}
please give answer if any one knows it
 
while implementing the gcm push notification with above code for android i got the error like Error=MissingRegistration
 
Thanks in Advance.
Posted 12-Nov-12 0:23am
Edited 12-Nov-12 1:44am
383.5K
v2
Comments
Member 9155024 at 27-Feb-13 6:40am
   
Did u find a solution regarding this error?? please let me know about it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 439
1 ChintanShukla 310
2 Gihan Liyanage 298
3 RyanDev 250
4 Richard Deeming 220
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,771
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100