Is there any way to broadcast an FCM notification--plus an image--to all devices, using C#?
Instead of sending to one specific device ID, I want to include an image and send to all devices over Firebase Notification service.
I used this code to send data to a single user device, but without an image:
public string SendNotificationInstaTips(string firebaseID,
string notTitle
string notText,
string notContent)
{
try
{
string SERVER_API_KEY = "AIza..QXq5OQCaM";
string SENDER_ID = "162..09";
string REGISTERATION_ID = firebaseID;
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
var data = new
{
to = REGISTERATION_ID,
data = new
{
title = notTitle,
text = notText
content = notContent
}
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
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();
return sResponseFromServer;
}
}
}
}
}
catch (Exception ex)
{
return ex.Message;
}
}