VIP Leiloes
VIP Leiloes

Reputation: 21

Cordova Android app do not receive FCM notifications from server side

I have been stuck in a Cordova Android app problem, I'm try to receive FCM notifications through Firebase plugin for Cordova, everytime I send notification through Firebase console the device receive the message, but when I try to use Firebase API on my server side, it says that the notifications it was send (status 200), but the device do not receive any notification.

Even when I try to test send notification by Postman, the same occurs, the send staus 200 appears, but no message arrives on the device.

My server side is build on .NET. Please, if someone could helpe me, I will apreciate.

Public Function SendNotificationToFirebaseCloud() As [String]
    Dim result = "-1"
    Dim webAddr = "https://fcm.googleapis.com/fcm/send"

    Dim httpWebRequest = DirectCast(WebRequest.Create(webAddr), HttpWebRequest)
    httpWebRequest.ContentType = "application/json"
    httpWebRequest.Headers.Add("Authorization:key=MY_AUTHORIZATION_KEY")
    httpWebRequest.Method = "POST"

    Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
        Dim json As String = "{""to"" : ""MY_FIREBASE_TOKEN"", ""priority"": ""high"", ""data"" : { ""name"" : ""VIP"", ""othername"" : ""Leiloes"" }}"
        streamWriter.Write(json)
        streamWriter.Flush()
    End Using

    Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
    Using streamReader = New StreamReader(httpResponse.GetResponseStream())
        result = streamReader.ReadToEnd()
    End Using

    Return result
End Function

Upvotes: 2

Views: 588

Answers (1)

nkayou
nkayou

Reputation: 271

You should have a "notification" field in your JSON, as the structure needs to be :

{
    "to" : "xxxx", 
    "priority" : "high", 
    "notification" : {
        "title" : "Your title",
        "body" : "Your body",
        "click_action" : "FCM_PLUGIN_ACTIVITY", //(This one is important as it's used to trigger the event when you click on the notification)
        "icon" : "myicon",
        "sound" : "default"
    },
    "data" : {
        "name" : "VIP", 
        "othername" : "Leiloes"
    }
}

Upvotes: 3

Related Questions