Created
October 6, 2017 09:57
-
-
Save NimzyMaina/de5a3de81105cc7b5a853071a3f027de to your computer and use it in GitHub Desktop.
Send FCM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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