Send web push notification to FIREFOX browser using ASP.NET C #

Can someone help me how to send web download notifications to Firefox browser (desktop and mobile)?

To send a push notification to a Chrome browser, I use the following steps. 1) Create an application in FCM (to get the sender ID and api key) 2) Get the endpoints (registration IDs) using the javascript method shown in google docs. 3) Sending push notifications to all registration identifiers using asp.net C #. Below is the code

protected void SubmitButton1_Click(object sender, EventArgs e) 
{
  AndroidPush(); // calling android push method
}

//Android push message to GCM server method
private void AndroidPush() 
{
  // your RegistrationID paste here which is received from GCM server.
  string regId = "APA91bG_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_V6hO2liMx-
  eIGAbG2cR4DiIgm5Q ";
    // applicationID means google Api key
  var applicationID = "AIzaSyDScBxxxxxxxxxxxxxxxxxxxpv66IfgA";
  // SENDER_ID is nothing but your ProjectID (from API Console- google code)//
  var SENDER_ID = "77xxxxx625";
  var value = Text1.Text; //message text box                                                                        
  WebRequest tRequest;
  tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
  tRequest.Method = "post";
  tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
  tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
  tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
  //Data post to server                                                                                                         
  string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + regId + "";
  Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  tRequest.ContentLength = byteArray.Length;
  Stream dataStream = tRequest.GetRequestStream();
  dataStream.Write(byteArray, 0, byteArray.Length);
  dataStream.Close();
  WebResponse tResponse = tRequest.GetResponse();
  dataStream = tResponse.GetResponseStream();
  StreamReader tReader = new StreamReader(dataStream);
  String sResponseFromServer = tReader.ReadToEnd(); //Get response from GCM server.
  Label3.Text = sResponseFromServer; //Assigning GCM response to Label text 
  tReader.Close();
  dataStream.Close();
  tResponse.Close();
}
+4
source share

Source: https://habr.com/ru/post/1655941/


All Articles