RSS

Push FCM Notification

06 Jul

using System.Web.Script.Serialization;

public void AndroidNotify(string applicationID, string senderId, string deviceId)
{
WebRequest tRequest = WebRequest.Create(“https://fcm.googleapis.com/fcm/send“);
tRequest.Method = “post”;
tRequest.ContentType = “application/json”;

var data = new
{
to = deviceId,
notification = new
{
body = “Asp Notification To Device” + DateTime.Now.ToLocalTime().ToString(),
title = “Notification”,
icon = “myicon”
}
};

var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
tRequest.Headers.Add(string.Format(“Authorization: key={0}”, applicationID));
tRequest.Headers.Add(string.Format(“Sender: id={0}”, senderId));
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
string str = sResponseFromServer;
Response.Write(“Response:” + str);
}
}
}
}
}

 

 

 
Leave a comment

Posted by on July 6, 2017 in asp.net

 

Leave a comment