Hi,
I'm trying to implement Firebase Cloud Messaging for Android. Unfortunately, I'm not able to handle all the cases required for a functional app. Note: It doesn't matter whether I send the notification via Cloud Functions of the Notifications Panel in the Firebase Console.
App is not started at all: When opening the app via double-tapping a notification, the notification is coming through via firebase.messaging().getInitialNotification()
.
_Note: The notification's message text doesn't show up here, no clue why_.
App is in foreground/active: When the app is in the foreground and a notification is sent, it's coming through via firebase.messaging().onMessage()
.
_Note: The notification's message text shows up here._
getInitialNotification()
(okay, makes sense) nor the getMessage()
(shouldn't happen) are triggered.I followed the Android setup guide for FCM step by step, and double-checked before posting this issue. Can anybody help please?
@skizzo this is quite strange as I definitely have this working in my app, though admittedly I most recently tested and confirmed it was working using the v2 PR: https://github.com/invertase/react-native-firebase/pull/130
My suggestion would be to start introducing some break points in the native Java code to see whether the message is being received at all by the app. In particular: https://github.com/invertase/react-native-firebase/blob/master/android/src/main/java/io/invertase/firebase/messaging/MessagingService.java#L20
Thanks for your reply @chrisbianca.
I've set a breakpoint in the onMessageReceived (..)
function in the MessagingService
class, and it's exactly what I expected: The function is being triggered in case 2 (_app is not started at all_, can't debug case 1) but not in case 3 (_app is started, but in background_).
Another thing I thought is that maybe it has to do with using background processing? I should note that I use react-native-audio-streaming in my project and want to be able to play music while the app is in the background.
Hi, we've recently got this working with v1.1.0.
Have you set launchMode="singleTop"
as described here:
http://invertase.io/react-native-firebase/#/installation-android?id=_3-cloud-messaging-optional
In this case you should receive the notification when returning from background using:
firebase.messaging().onMessage()
Since the code here:
https://github.com/invertase/react-native-firebase/blob/master/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessaging.java
sends the notification event in onNewIntent
As mentioned, I followed the instructions and double-checked before creating this issue. So yes, the launchMode
is set to singleTop
. And thanks, but knowing that I should receive notifications now doesn't really get me any closer to solving this ;)
Is it normal for you guys that the onNewIntent (..)
function is called every time I start the app or put it into the foreground, without actively sending any notifications? This also means that I receive this intent on every app start, even though it's not a notification directly:
Maybe it has sth. to do with it? Needless to say that I come from the iOS world and am an Android noob still.
Hi, I'm also an android noob, and just a user of this library.
What we've done is ignore the events that are irrelevant (don't contain the notification data we need).
Inter process communication in Android works by launching activities with intents (intents contain the data passed to the activity).
Meaning when you press a notification it will launch your app (activity) with the notification data (intent).
In singleTop
mode instead of creating a new activity with a new intent, the data is passed to the existing activity using the onNewIntent
as described here:
https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en
I would suggest putting some logs in this handler and see if you get the notification you're looking for.
Thanks for the explanation! I already placed breakpoints & logs in all the Java functions handling notifications (see my last comment), so I'm really running out of ideas here.
@skizzo do you want to give the v2 branch a try?
I've done a bit of clean up of Firebase Messaging and confirmed that your scenario is working in my app, so hopefully it will resolve your problem as well.
also having this issue.
"react": "16.0.0-alpha.12",
"react-native": "^0.45.1",
"react-native-firebase": "1.1.1",
Seems not to get all the data in RNFirebaseMessaging.java
private WritableMap parseIntent(Intent intent)
When app is active the registerMessageHandler is used and that works great.
when app is in background the registerMessageHandler is runned, but the app is inactive so it doesn't do anything. going back to the app parseIntent is runned and doesn't show the correct object to the app
when app is closed the parseIntent is runned and doesn't show the correct object to the app
@fbacker when you say that it doesn't show the correct object to the app, what exactly do you mean by this? That onMessage
has the incorrect notification object? Or that a notification isn't showing?
When app is opened.
and when its closed
Thanks @fbacker. Are you able to confirm this is still the case with v2.0.0 which has just been released? I'll have some time tomorrow to investigate this properly.
@chrisbianca Yes, will upgrade and try it out.
Upgraded to v2, but still same issue.
I've inactivated the app, send a push notification and open the app. Even when I click on the notification to open the app I still doesn't get the fcm object.
+1 same issue.
Same issue here as well.
+1 same issue.
I was experiencing the same issue, and when sending a notification through a firebase cloud function or otherwise, I had code that looked like this.
const payload = {
notification: {
data: myData
}
}
firebase.messaging().sendToTopic(userTopic, payload)
but it turns out that if you want to append extra data to the notification your syntax has to look like this
const payload = {
notification: {
options: myNotificationOptions
},
data: {
payloadData: myData
}
}
firebase.messaging().sendToTopic(userTopic, payload)
not sure if the people experiencing this problem are already doing this but this fixed everything for me, hope it helps.
Any solution? I have the same problem, I am trying to use the library in conjunction with react-native-navigation
I tried this,
const payload = {
notification: {
options: myNotificationOptions
},
data: {
payloadData: myData
}
}
only works if myData is a String
Error sending message (or deleting call): { Error: Messaging payload contains an invalid value for the "data.payloadData" property. Values must be strings.
So I am back to this...
const payload = {
notification: {
options: myNotificationOptions
},
data: myData // myData is a Map
which works fine if the app is open, however when closed, and the notification comes, all values are null
Hi, any progress on that? Or workaround/patch? I have the same problem
We ran into this issue as well (or something very similar), and it turned out that it was our Java-implementation of a splash screen that broke notifications for us. Implemented by following this guide.
We also had custom splash screen. Our solution for this issue was to send in notification payload this key click_action: "open_event_action"
,
Notification payload:
"notification": {
"title": "Title",
"body": "Body",
"click_action": "open_event_action"
},
"data": {
"eventId": "1",
"read": "false"
}
then modify AndroidManifest file by adding intent-filter for that click action.
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:background="@color/background"
android:launchMode="singleTop"
>
<intent-filter>
<action android:name="open_event_action" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Thanks for reporting. We're aware of lots of issues with notifications and will be addressing them all as part of the v3.2.0 release stream. Please see https://github.com/invertase/react-native-firebase/issues/595 for updates.
Good news, the long awaited alpha of our messaging and notifications overhaul is now available!!
Check out the release notes here: https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0-alpha.1
If you have any comments and suggestions or want to report an issue, come find us on Discord
I had to remove my custom SplashScreen to get it to work on Android. Maybe I'll try the library react-native-splash-screen
suggested on this thread.
Most helpful comment
We also had custom splash screen. Our solution for this issue was to send in notification payload this key
click_action: "open_event_action"
,Notification payload:
then modify AndroidManifest file by adding intent-filter for that click action.