Hi, I'm using RN 33 and fcm 2.1.0. When I send data only messages while my app is running in the background the app receives the messages. When I send notifications with or without data and/or content_available the notifications get received by android but when they are clicked on the app doesn't receive the message in any of the message receipt routines. If the app is not running the message comes into initialnotification as would be expected.
Please help me understand how to have a notification click get received by the app when running in the background as it comes to the foreground.
thanks
OK, it looks like this was my mistake for not calling getInitialNotification each time my app returns from the background to the foreground. However, now that I'm doing that I'm calling getInitialNotification every time the app returns to the foreground I continually get the same initial data if it was the user that brought it to the foreground by task switching. Is there a way to clear out the initial notification after is has been processed?
@jcharbo I managed to get this working correctly without needing to handle app state change. The data payload should be coming through to your FCM.on('notification') handler. Mine wasn't because I had overridden onNewIntent() in MainActivity.java because of react-native-branch. I had to add super.onNewIntent(intent) to the function in order for it a propogate to this module. Once I did that I was getting the notification correctly :). I now only use getInitialNotification() in my componentDidMount()
@lukefanning you are right. @jcharbo you should only use get initial notification when the app starts. all following notification happen when app is fore or background goes to notification event.
@lukefanning where should I put super.onNewIntent(intent)?
Also,
When app is not running and user clicks notification, notification data will be passed into FCM.initialData
FCM.initialData is undefined
@sibelius In onNewIntent() in MainActivity.java.
Yep FCM.initialData isn't how you retrieve the initial data (docs could use some tweaking there), you need to use FCM.getInitialNotification().then(notif => {yourcode});
@lukefanning even on >=RN33 ?
@sibelius oh no sorry I only had to do that because I had overridden the function because of react-native-branch. If you haven't overridden the function then you shouldn't need to add it on the latest RN.
@sibelius yes it is breaking change in v2.2
I'm sorry, but this is not clear on README, I'll try this tks
That's my MyActivity.java
package myapp;
import android.content.Intent;
import com.facebook.react.ReactActivity;
import com.evollu.react.fcm.FIRMessagingPackage;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "App";
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
}
FCM.getInitialNotification().then((data) => {
always return this: { opened_from_tray: 1, fcm: { action: null } } when I click in any push notification
that's my firebase payload
const payload = {
to: 'my token',
data: {
title: 'my title',
body: 'my body',
url: 'app://deeplink',
},
notification: {
icon: 'ic_notification',
color: '#e34056',
title: 'my title',
body: 'my body',
},
click_action: 'fcm.action.MYACTION',
priority: 10,
};
will update readme
@sibelius you don't need these unless there are conflicts like @lukefanning
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
@sibelius updates?
FCM.getInitialNotification() still do not work on android
ios behavior is working fine
@sibelius can you add break point in android native code FIRMessagingModule and see what is happening when getInitialNotification is called?
I'll do that
right now I have a new problem
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
my guess is that com.google.android.gms:play-services-gcm:9.4.0 is conflicting with another dep of my project, when I fixed this I will debug more the android code
@sibelius @evollu @lukefanning
Have react native RN 0.32, fcm version "1.1.0", need to get initialnotification. Right now getting this in FCM

This is my mainApplication.java
`import android.support.annotation.NonNull;
import com.facebook.react.ReactPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.reactnativenavigation.NavigationApplication;
import com.evollu.react.fcm.FIRMessagingPackage;
import java.util.Arrays;
import java.util.List;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import io.neson.react.notification.NotificationPackage;
import com.lugg.ReactSnackbar.ReactSnackbarPackage;
public class MainApplication extends NavigationApplication {
@Override
public boolean isDebug() {
// Make sure you are using BuildConfig from your own application
return BuildConfig.DEBUG;
}
@NonNull
@Override
public List
return Arrays.
new RNDeviceInfo(),
new FIRMessagingPackage(),
new VectorIconsPackage(),
new NotificationPackage(),
new ReactSnackbarPackage()
);
}
}
`
This is my mainActivity.java
`import android.os.Bundle;
import android.support.annotation.Nullable;
import com.reactnativenavigation.controllers.SplashActivity;
public class MainActivity extends SplashActivity {
}`
Need Help.
regarding the is error, remove your code that calls presentnotification
private WritableMap parseIntent(Intent intent){
WritableMap params;
Bundle extras = intent.getExtras();
if (extras != null) {
try {
params = Arguments.fromBundle(extras);
} catch (Exception e){
Log.e(TAG, e.getMessage());
params = Arguments.createMap();
}
} else {
params = Arguments.createMap();
}
WritableMap fcm = Arguments.createMap();
fcm.putString("action", intent.getAction());
params.putMap("fcm", fcm);
params.putInt("opened_from_tray", 1);
return params;
}
I've added a breaking point on rn-fcm package on android, and intent.getExtras() is null
my firebase payload is as follow: https://github.com/evollu/react-native-fcm/issues/111#issuecomment-249564574
@sibelius in your payload it seems missing a , before notification
sorry about that, this was just a typo in my comment, there is a , in there in my server code, just updated the comment 馃憤
can you add break point in MessagingService.
RemoteMessage in MessagingService is correct
my problem it is in this line: https://github.com/evollu/react-native-fcm/blob/master/android/src/main/java/com/evollu/react/fcm/FIRLocalMessagingHelper.java#L58
I have a splash screen that it is my main activity, that calls my real MainActivity, so the intent goes to that another activity instead of the reactActivity
do u think it is possible to get the ReactActivity instead of the main activity?
hmm tricky then. you can send a new intent to ReactActivity from your main activity to bridge it
hmm, I've noticed that there is a getActivity() on FIRMessagingModule, isn't that enough to fix this?
that is getting react activity, not the main activity I think.
It is better to make react modules living within react domain.
how can I send a new intent to my ReactActivity from the SplashActivity?
create a new intent with the content of the intent and target react native's class.
something like this.
Intent intent = new Intent(mContext, FIRLocalMessagingPublisher.class);
mContext.sendOrderedBroadcast(i, null);
Why do you set your splash as your main activity? I'm using rn-splash-screen
I'll take a look on https://github.com/mehcode/rn-splash-screen
tks for all the support, that was the problem.
I'm using just the MainActivity and getInitialNotification is working
u can close this as well!
馃帀 馃殌
cool
tks for all the support, that was the problem.
@sibelius, could you please elaborate on what exactly you mean by "that was the problem" and how you fixed it?
My main activity was a Splash screen instead of using the MainActivity that extends ReactActivity
This package send an Intent to the main activity, so my SplashActivity received the intent instead of the MainActivity
I've used rn-splash-screen to avoid using another activity for splash purposes
Hi guys,
when i try to follow the instructions above, I'm getting this kind of error.

Is there something that i missed?
@Ethan0007 use the latest version of react native
@sibelius it work for now sir, i just missed something in my code.
Thank you!
Most helpful comment
My main activity was a Splash screen instead of using the MainActivity that extends ReactActivity
This package send an Intent to the main activity, so my SplashActivity received the intent instead of the MainActivity
I've used rn-splash-screen to avoid using another activity for splash purposes