React-native-notifications: [Android] getInitialNotification not working

Created on 15 Sep 2019  路  8Comments  路  Source: wix/react-native-notifications

I have installed the latest version of this package. I have made the link manually on Android according to the guide.

Everything works: NotificationsAndroid.setNotificationOpenedListener, NotificationsAndroid.setRegistrationTokenUpdateListener, etc. and in iOS also everything is fine.

But PendingNotifications.getInitialNotification() always return _N/A (false)_, so I can't get the payload when a notification is openen and the app was closed.

I use:

"react-native": "0.60.5",
"react-native-navigation": "^3.1.2",
"react-native-notifications": "^2.1.0"

Any ideas what could be wrong?

bug

Most helpful comment

@CristianOspina What service are you using to test it? I had the same problem because I tried to send a notification directly from Firebase console. But this perhaps sends only Notification Message and you have to send Data Message to notification be passed into onMessageReceived method (see https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages).

If I send following HTTP POST request to https://fcm.googleapis.com/fcm/send (via curl or Postman for example) it works for both, the app on the background and killed app:

Headers:

Content-Type: application/json
Authorization: key=<SERVER_KEY>

Body:

{
 "to" : "DEVICE_TOKEN",
 "data" : {
     "body" : "Body of Your Notification in Data",
     "title": "Title of Your Notification in Title",
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
 }
}

All 8 comments

The workaround in https://github.com/wix/react-native-notifications/issues/326#issuecomment-507371366 works but only when the app is killed. If the app is in background I still can't get the notification.

Can't reproduce it in our example project and it also doesn't reproduce in our production app. can you elaborate? maybe it's something with the payload itself?

@CristianOspina What service are you using to test it? I had the same problem because I tried to send a notification directly from Firebase console. But this perhaps sends only Notification Message and you have to send Data Message to notification be passed into onMessageReceived method (see https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages).

If I send following HTTP POST request to https://fcm.googleapis.com/fcm/send (via curl or Postman for example) it works for both, the app on the background and killed app:

Headers:

Content-Type: application/json
Authorization: key=<SERVER_KEY>

Body:

{
 "to" : "DEVICE_TOKEN",
 "data" : {
     "body" : "Body of Your Notification in Data",
     "title": "Title of Your Notification in Title",
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
 }
}

Can confirm what @jakubkoci stated.

PendingNotifications.getInitialNotification() works as expected when sending a test push notification through a HTTP POST request instead of the firebase console.

Right. It works now. Sorry for the delay and thank you!

Thanks @jakubkoci , helped alot..

Any idea how to deal with this in server (Admin SDK) environment ?
cuz my current is giving me undefined notification.

sendMulticast({
  notification: { ... }
  data: { ... }
  android: { notification, data }
  // or anything else
})

Ok, got it.
I just had to delete the notification nodes

I tried deleting the notification node which is working fine.
But unable to get notification image after removing.
any idea?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fosteruk picture fosteruk  路  5Comments

moonjava2005 picture moonjava2005  路  5Comments

denissb picture denissb  路  5Comments

puremana picture puremana  路  5Comments

daominhsangvn picture daominhsangvn  路  6Comments