Skip to content

Instantly share code, notes, and snippets.

@NimzyMaina
Created October 6, 2017 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NimzyMaina/de5a3de81105cc7b5a853071a3f027de to your computer and use it in GitHub Desktop.
Save NimzyMaina/de5a3de81105cc7b5a853071a3f027de to your computer and use it in GitHub Desktop.
Send FCM
public async Task<bool> SendPushNotification()
{
var applicationID = "xxx";
var senderId = "xxx";
var deviceId = "xxxx"
using (var client = new HttpClient())
{
//do something with http client
client.BaseAddress = new Uri("https://fcm.googleapis.com");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"key={applicationID}");
client.DefaultRequestHeaders.TryAddWithoutValidation("Sender", $"id={senderId}");
var data = new
{
to = deviceId,
notification = new
{
body = "This is the message Body",
title = "This is the title of Message",
icon = "myicon"
},
priority = "high"
};
var json = JsonConvert.SerializeObject(data);
var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
var result = await client.PostAsync("/fcm/send", httpContent);
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment