Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please share the source code for sending notifications from asp.net to android applications. Or else please share the step by step process. Thanks Much..

I tried with the below code but it is not sending the notification. Please correct me if I am wrong.
C#
bool isPushMessageSend = false;
       string pushMessage = "Test Push from .Net";
       string postString = "";
       string urlpath = "https://api.parse.com/1/push";
       var httpWebRequest = (HttpWebRequest)WebRequest.Create(urlpath);
       postString = "{ \"channels\": [ \"\"  ], " + "\"deviceType\": \"android\", " + "\"data\" : {\"alert\":\"" + pushMessage + "\"}" + "}";
       httpWebRequest.ContentType = "application/json";
       httpWebRequest.ContentLength = postString.Length;
       httpWebRequest.Headers.Add("X-Parse-Application-Id", "MyAppID");
       httpWebRequest.Headers.Add("X-Parse-REST-API-KEY", "MyAppRESTkey");
       httpWebRequest.Method = "POST";
       StreamWriter requestWriter = new StreamWriter(httpWebRequest.GetRequestStream());
       requestWriter.Write(postString);
       requestWriter.Close();
       var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
       using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
       {
           var responseText = streamReader.ReadToEnd();
           JObject jObjRes = JObject.Parse(responseText);
           if (Convert.ToString(jObjRes).IndexOf("true") != -1)
           {
               isPushMessageSend = true;
           }
       }
Posted
Updated 21-May-14 3:14am
v2

1 solution

Hello Balakrishnan,

Please have a look at the Push Notification Tutorial[^] available on the PARSE website. They also have the source code for the tutorial.

Regards,
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900