Hi guys,
Hope you are doing great, for me no issue is i finally be able to send push notifications from console and also from my dot net application. but i stuck in when app is closed i can’t be able to receive notifications.
Sharing the code what i did with my dot net app to send push notifications and it works fine.
WebRequest tRequest = WebRequest.Create(“https://fcm.googleapis.com/fcm/send”);
tRequest.Method = “POST”;
tRequest.ContentType = “application/json”;
var data1 = new
{
to = deviceId,
notification = new
{
title = “Hurray!”,
body = “The session has been started.Please come into Main Ballroom”,
sound = “Enabled”
}
};
string json = Newtonsoft.Json.JsonConvert.SerializeObject(data1);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
tRequest.ContentLength = byteArray.Length;
tRequest.ContentType = "application/json";
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();
str = sResponseFromServer;
}
}
}
}
}
catch (Exception ex)
{
str = ex.Message;
}
i hope you guys will help me on this.
Thanks