0

I am successfully sent push notifications to FireBase Cloud Messaging(FCM) from server in order to send them to android device. But I don't know why FCM does not send those notifications to device.

My code is as below,

Notification to FCM from server(C#)

public static void SendPushNotification() { string serverKey = "AAAA...z"; try { var result = "-1"; var webAddr = "https://fcm.googleapis.com/fcm/send"; var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization:key=" + serverKey); httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"to\": \"f..A:..p_G\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}"; streamWriter.Write(json); streamWriter.Flush(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } } catch (Exception ex) { Response.Write(ex.Message); } } 

My response for the above request

{"multicast_id":5002368547300,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:14200031%09c4rrr5787egg"}]}

I am assuming that once FCM receives new notifications, it will push those notifications to respective android devices.

But for me, it is not working.

5
  • I don't know there is anything must be done on mobile app side to receive notifications. Commented Jun 1, 2018 at 7:48
  • It looks like you are s nding a data message to the device. Data messages don't automatically show notifications. You have to implement the FirebaseMessagingService and handle data messages in onMessageReceived callback Commented Jun 1, 2018 at 20:14
  • Yes. I got it for notification messages and it is working. But I don't know how to process data messages. Can u send some sample code? Commented Jun 2, 2018 at 7:16
  • See the FCM sample app that demonstrates this: github.com/firebase/quickstart-android/tree/master/messaging/… Commented Jun 3, 2018 at 23:32
  • There is no getData() method available. Meanwhile I got a solution from forums.xamarin.com/discussion/62903/…. Commented Jun 4, 2018 at 10:01

1 Answer 1

0

I got a solution by referring the below link

Firebase push notification not showing on phone despite successful response

Once I changed the 'json' string as mentioned in above link, it is working.

Sign up to request clarification or add additional context in comments.

1 Comment

It may be helpful to know about the syntax from firebase.google.com/docs/cloud-messaging/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.