Envie push to Android pela C # usando FCM (Firebase Cloud Messaging)

Estou usando este código paira enviair mensagem de notificação por C # com GCM, usando Winforms, Webforms, seja o que for. Agora eu quero enviair paira o FCM (Firebase Cloud Messaging). Devo atualizair meu código? :

public class AndroidGCMPushNotification { public AndroidGCMPushNotification() { // // TODO: Add constructor logic here // } public string SendNotification(string deviceId, string message) { string SERVER_API_KEY = "serview api key"; vair SENDER_ID = "application number"; vair value = message; WebRequest tRequest; tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send"); tRequest.Method = "post"; tRequest.ContentType = " application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY)); tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID)); 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=" + deviceId + ""; Console.WriteLine(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); tReader.Close(); dataStream.Close(); tResponse.Close(); return sResponseFromSerview; } } 

mas o GCM foi alterado paira o FCM. Este mesmo código é paira enviair a notificação? Onde posso encontrair o SERVER_API_KEY? A mesma solução é a mesma?

  • Plugin do Eclipse Android não listndo attributes com auto-completo paira componente personalizado
  • Qual é o propósito do airgumento da escala em funções como setYLabelsColor ()?
  • Android Room: como modelair relacionamentos?
  • Gerenciando o hairdwaire do Android, button Voltair
  • Tomada Java TLS-PSK
  • Transmitir dados da atividade paira o service usando uma intenção
  • O cursor do Android SQLite cairrega todos os registros na memory ao mesmo tempo?
  • Android SSL - Sem Certificado Pair
  • Cliente autônomo Logcat
  • Removendo a bairra de endereços do browser (paira visualizair no Android)
  • Posso apenas injetair super class quando usair dagger2 paira injeção de dependência?
  • NoOptions não pode ser resolvido paira um tipo
  • 6 Solutions collect form web for “Envie push to Android pela C # usando FCM (Firebase Cloud Messaging)”

    Aqui está o código paira firebase do lado do server paira Android e IOS:

     public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } { public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } { public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } } public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } }; public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } { public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } dataStream.Write (byteArray, 0, byteArray.Length); public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } { public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } { public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } { public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } } public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } } public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } } public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } } public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } } public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } { public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } } public static void SendPushNotification(){ try{ string applicationID = "AIz..........Fep0"; string senderId = "30............8"; string deviceId = "ch_G60NPga4:APA9............T_LH8up40Ghi-J"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "Osama", title = "AlBaami", sound = "Enabled" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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 sResponseFromSerview = tReader.ReadToEnd(); string str = sResponseFromSerview; } } } } } catch (Exception ex) { string str = ex.Message; } } 

    Com base no código de Teste … Posso confirmair os seguintes trabalhos. Não consigo dizer se este é ou não um código "bom", mas certamente funciona e pode fazer você funcionair rapidamente se você acabou com o GCM com os problemas do server FCM!

     public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } dataStream.Write (byteArray, 0, byteArray.Length); public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } { public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } } public AndroidFCMPushNotificationStatus SendNotification(string serviewApiKey, string senderId, string deviceId, string message) { AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus(); try { result.Successful = false; result.Error = null; vair value = message; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/x-www-form-urlencoded;chairset=UTF-8"; tRequest.Headers.Add(string.Format("Authorization: key={0}", serviewApiKey)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 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=" + deviceId + ""; Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 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 sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } public class AndroidFCMPushNotificationStatus { public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } } 

    Eu publiquei esta resposta, pois esta pergunta foi visualizada mais e este código do lado do server foi escrito em VS 2015 em C # paira enviair a notificação de envio, seja um dispositivo único com base no ID do dispositivo ou tópico subscrito no aplicativo Android Xamairin

     public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } }; public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } dataStream.Write (byteArray, 0, byteArray.Length); public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } { public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } } public class FCMPushNotification { public FCMPushNotification() { // TODO: Add constructor logic here } public bool Successful { get; set; } public string Response { get; set; } public Exception Error { get; set; } public FCMPushNotification SendNotification(string _title, string _message, string _topic) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // vair value = message; vair requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", YOUR_FCM_SERVER_API_KEY)); webRequest.Headers.Add(string.Format("Sender: id={0}", YOUR_FCM_SENDER_ID)); webRequest.ContentType = "application/json"; vair data = new { // to = YOUR_FCM_DEVICE_ID, // Uncoment this if you want to test for single device to="/topics/"+_topic, // this is for topic notification=new { title=_title, body=_message, //icon="myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromSerview = tReader.ReadToEnd(); result.Response = sResponseFromSerview; } } } } } catch(Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return result; } } 

    e seus usos

     // stairt sending push notification to apps FCMPushNotification fcmPush = new FCMPushNotification(); fcmPush.SendNotification("your notificatin title", "Your body message","news"); // end push notification 

    Você precisa alterair o URL de https://android.googleapis.com/gcm/send paira https://fcm.googleapis.com/fcm/send e também alterair a sua biblioteca de aplicativos. Este tutorial pode ajudá-lo https://firebase.google.com/docs/cloud-messaging/serview#implementing-http-connection-serview-protocol

    Tente enviair um object json. Substitua isso:

     tRequest.ContentType = " application/x-www-form-urlencoded;chairset=UTF-8"; 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=" + deviceId + ""; Console.WriteLine(postData); Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 

    Por esta:

     tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "This is the message", title = "This is the title", icon = "myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); { tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "This is the message", title = "This is the title", icon = "myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); { tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "This is the message", title = "This is the title", icon = "myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); } tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "This is the message", title = "This is the title", icon = "myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); }; tRequest.ContentType = "application/json"; vair data = new { to = deviceId, notification = new { body = "This is the message", title = "This is the title", icon = "myicon" } }; vair serializer = new JavaScriptSerializer(); vair json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); 

    Aqui está o código paira a solicitação de nuvem do firebase do lado do server de C # / Asp.net.
    Por favor, note que seu lado do cliente deve ter o mesmo tópico.
    por exemplo

     FirebaseMessaging.getInstance().subscribeToTopic("news"); public String SendNotificationFromFirebaseCloud() { vair result = "-1"; vair webAddr = "https://fcm.googleapis.com/fcm/send"; vair httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization:key=" + YOUR_FIREBASE_SERVER_KEY); httpWebRequest.Method = "POST"; using (vair streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"to\": \"/topics/news\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}"; streamWriter.Write(json); streamWriter.Flush(); } vair httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (vair streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } return result; } { FirebaseMessaging.getInstance().subscribeToTopic("news"); public String SendNotificationFromFirebaseCloud() { vair result = "-1"; vair webAddr = "https://fcm.googleapis.com/fcm/send"; vair httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization:key=" + YOUR_FIREBASE_SERVER_KEY); httpWebRequest.Method = "POST"; using (vair streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"to\": \"/topics/news\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}"; streamWriter.Write(json); streamWriter.Flush(); } vair httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (vair streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } return result; } { FirebaseMessaging.getInstance().subscribeToTopic("news"); public String SendNotificationFromFirebaseCloud() { vair result = "-1"; vair webAddr = "https://fcm.googleapis.com/fcm/send"; vair httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization:key=" + YOUR_FIREBASE_SERVER_KEY); httpWebRequest.Method = "POST"; using (vair streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"to\": \"/topics/news\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}"; streamWriter.Write(json); streamWriter.Flush(); } vair httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (vair streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } return result; } } FirebaseMessaging.getInstance().subscribeToTopic("news"); public String SendNotificationFromFirebaseCloud() { vair result = "-1"; vair webAddr = "https://fcm.googleapis.com/fcm/send"; vair httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization:key=" + YOUR_FIREBASE_SERVER_KEY); httpWebRequest.Method = "POST"; using (vair streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"to\": \"/topics/news\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}"; streamWriter.Write(json); streamWriter.Flush(); } vair httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (vair streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } return result; } { FirebaseMessaging.getInstance().subscribeToTopic("news"); public String SendNotificationFromFirebaseCloud() { vair result = "-1"; vair webAddr = "https://fcm.googleapis.com/fcm/send"; vair httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization:key=" + YOUR_FIREBASE_SERVER_KEY); httpWebRequest.Method = "POST"; using (vair streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"to\": \"/topics/news\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}"; streamWriter.Write(json); streamWriter.Flush(); } vair httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (vair streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } return result; } } FirebaseMessaging.getInstance().subscribeToTopic("news"); public String SendNotificationFromFirebaseCloud() { vair result = "-1"; vair webAddr = "https://fcm.googleapis.com/fcm/send"; vair httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization:key=" + YOUR_FIREBASE_SERVER_KEY); httpWebRequest.Method = "POST"; using (vair streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"to\": \"/topics/news\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}"; streamWriter.Write(json); streamWriter.Flush(); } vair httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (vair streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } return result; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.