Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Push Notification Using Firebase Cloud Messaging Using .NET
WhatsApp
Gitesh Warhade
7y
81.9
k
0
5
25
Blog
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
Steps to get server key / SenderID
To get the keys, log in to Firebase account.
Select the project from the list.
Click on "Setting" gear icon and click "Project Settings".
Click on "Cloud Messaging" tab to select "Server key" and "Sender key" from the below screen.
Add the below code to send push notifications.
//Create the web request with fire base API
WebRequest tRequest = WebRequest.Create(
"https://fcm.googleapis.com/fcm/send"
);
tRequest.Method =
"post"
;
//serverKey - Key from Firebase cloud messaging server
tRequest.Headers.Add(string.Format(
"Authorization: key={0}"
, serverKey));
//Sender Id - From firebase project setting
tRequest.Headers.Add(string.Format(
"Sender: id={0}"
, senderId));
tRequest.ContentType =
"application/json"
;
var
payload =
new
{
to = deviceId,
priority =
"high"
,
content_available =
true
,
notification =
new
{
body = txtmsg,
title = txttitle.Replace(
":"
,
""
),
sound =
"sound.caf"
,
badge = badgeCounter
},
};
var
serializer =
new
JavaScriptSerializer();
Byte[] byteArray = Encoding.UTF8.GetBytes(payload);
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()) {
if
(dataStreamResponse !=
null
) using(StreamReader tReader =
new
StreamReader(dataStreamResponse)) {
String sResponseFromServer = tReader.ReadToEnd();
result.Response = sResponseFromServer;
}
}
}
}
Firebase
cloud Messaging
Push notification
.NET
Up Next
Understanding .NET Framework, .NET Core, .NET Standard And Future .NET
Ebook Download
View all
.NET Interview Questions and Answer: Practical Implementation
Read by 41.9k people
Download Now!
Learn
View all
Membership not found