getInitialNotification is null if app is closed and opened from banner. Additional data in custom_notification
See original GitHub issueWhat version of RN and react-native-fcm are you running? “react-native”: “0.46.4”, “react-native-fcm”: “^9.1.0”,
What device are you using? (e.g iOS9 emulator, Android 6 device)? android device nexus 5x
Is your app running in foreground, background or not running?
- Iam not able to achieve this behaviour: If app is closed (not running) and I receive notification, I want to show the notification and then be able to know, if the app was opened by clicking the banner, or app icon. I also expect to know if the banner was clicked when app is opened / in background, but that works fine (except the second question part below).
I send custom_notification payload to fcm according to docs, so after receiving silentNotification (with no notification payload) I let this package to build a local notification. But in both cases, whether I open the app by clicking the notification banner or app icon I get null value returned from FCM.getInitialNotification(). Does anybody know how to achieve the expected behaviour? I have spend too much time looking for answer here, but with no luck.
- Also I noticed that after clicking banner and receiving second notification with opened_from_tray value, I lost any additional data I send with originial notification, to make it really clear, I send:
{
"to":"FCM_TOKEN",
"data": {
"custom_notification": {
"body": "test body",
"title": "test title",
"color":"#00ACD4",
"priority":"high",
"icon":"ic_notification",
"show_in_foreground": true
},
"someOtherData":"data", //this gets lost
"someEvenMoreOtherData":"data2", //this gets lost
}
}
after clicking the banner I receive:
body:"test body",
color:"#00ACD4",
fcm:{action: null},
icon:"ic_notification",
opened_from_tray:1,
priority:"high",
show_in_foreground:true,
title:"test title",
so just what is in custom_notification, so should I send my additional data also in custom_notification?
also my manifest file
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/SplashTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- FCM START-->
<intent-filter>
<action android:name="fcm.ACTION.HELLO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- FCM END-->
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<!-- FCM START -->
<service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher"/>
<receiver android:enabled="true" android:exported="true" android:name="com.evollu.react.fcm.FIRSystemBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (8 by maintainers)
Top GitHub Comments
I was having this issue as well. I am using
react-native-splash-screen
, which has its own launch activity:SplashActivity
.The issue is that
MessagingService
is sending itsIntent
message toSplashActivity
, which then startsMainActivity
, and the message is lost. The solution is simple: just add the following line toSplashActivity
after the intent is constructed:This copies over the “extras” from
MessagingService
’s intent over to the newMainActivity
intent, enablingFIRMessagingModule
to later extract these extras and send them across the bridge to JavaScript.@Ashoat Thanks a lot for this. it was just what I was missing 💯