0

I implemented Firebase cloud messaging in my Android app and also setup the Firebase console. Those are working perfectly so far for

  1. App in foreground
  2. App in background

But not when my app was killed. According to this answer for point 1.2:

Data Messages: Theses messages trigger the onMessageReceived() callback even if your app is in foreground/background/killed

What am I missing to receive data for killed apps?

Here the json I pass:

{
    "to": "/topics/testTopic",
    "data": {
        "key1" : "val1",
        "key2" : true
     }
}

I applied the example in the link above in point 2.

Murat Ceven
  • 264
  • 1
  • 6

1 Answers1

1

enter image description here

Authorization key will be your server key in the attached Image

{

“data”: { “score”: “45×1”,

“time”: “15:10”

},

“to” : “your server key” }`

About above JSON Format you need to pass from the app server:

“data” will contain your key value pair coming from the server. “to” will be your fcm token, Authorization you will get from the FCM Console -> Setting – >Project setting -> Cloud Messaging and there copy your server key.

Vishvendu Palawat
  • 566
  • 10
  • 29
  • Accroding to here: https://stackoverflow.com/a/37845174/7592495 we would use the server key twice, since it is used in the POST request in of the headers already. – Murat Ceven Sep 12 '17 at 09:39
  • You wrote both are server keys, but they obviously differ. I already got Authorization key (see POST header) properly from: FCM Console -> Setting – >Project setting -> Cloud Messaging and there copy your server key (and thats working so far). In the JSON the content of "to".. where is that from? – Murat Ceven Sep 12 '17 at 11:00
  • Ok thats the registration token from `String token = FirebaseInstanceId.getInstance().getToken();` – Murat Ceven Sep 12 '17 at 11:25
  • to is your fcm token and in the header is your server key – Vishvendu Palawat Sep 12 '17 at 11:25
  • Ok its working thnx Brat. So triggering killed apps is possible via fcm token only? And not with /topics/xy right? – Murat Ceven Sep 12 '17 at 11:28
  • Yes you need to send payload in the json format if you want to invoke onreceive method of FCM when app is not running – Vishvendu Palawat Sep 12 '17 at 11:29
  • Yes but I am interessted to invoke not with fcm token only, also with the topics like `"to": "/topics/testTopic"` in JSON format – Murat Ceven Sep 12 '17 at 11:38