I'm using v3.1.1 of the library. When I receive background notification and tap on it, it opens my app, however Notifications.getInitialNotification() nor Notifications.events().registerNotificationReceivedBackground are triggered or have data.
Possibly related issue: https://github.com/wix/react-native-notifications/issues/445
Interestingly notifications that are received in foreground don't have this issue. If I receive notification in foreground, close my app and then click on such notification I am seeing correct behaviour in the app.
Foreground notifications come with problem of their own described here (they are empty) https://github.com/wix/react-native-notifications/issues/456
the event that's triggered is registerNotificationOpened
it's not triggered registerNotificationOpened on Android
version 3.1.1
RN: 0.60.4
android: 6.0.1
Experiencing the same issue. registerNotificationOpened is not triggered on Android. With iOS no problems occur.. https://github.com/wix/react-native-notifications/issues/498 and https://github.com/wix/react-native-notifications/issues/482 might be related
Any update on this issue?
Unfortunately not, still can鈥檛 figure out how to get it working on Android with the correct events.
Maybe this PR resolves the issue https://github.com/wix/react-native-notifications/pull/527/files
Experiencing the same issue :(
same issue here, and can't find a solution in any of the issue threads :(
Running into same issue
Hi, I too had faced the same kind of issue so I am posting my findings here.
First we need to understand when the notification is received and where it's sent from as the behavior depends on both these aspects.
Now let's mix and match these cases and see from where we can get the payload:
registerNotificationOpenedregisterNotificationOpenedgetInitialNotificationNow why does this occur:
As per Handling Messages, the notifications that are generated using Admin SDK are received by this library code, whereas the notifications that are sent by the FCM console are received by the Firebase SDK and the notification is generated by it. Now in this case the data payload is delivered in the extras of the intent of your launcher Activity.
You can get this data from your launcher activity's; This can be verified using:
By adding this in your launcher activity; For the sake of simplicity the code considers a random timer of 10 seconds to allow the listener to be set otherwise the event will be emitted before the listener is attached, but you can get the data using some native method which gets called from the JS instead of this timer
)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent.getExtras() != null && intent.getExtras().keySet().contains("someparameterfromnotificationascheck")) {
Log.d("Test", intent.getExtras().toString());
JsIOHelper jsIOHelper = new JsIOHelper();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
jsIOHelper.sendEventToJS("consolenotification", getIntent().getExtras(), getReactInstanceManager().getCurrentReactContext());
}
}, 10000);
}
}
And by adding this in your JS where you want the notification
this.emitter = new NativeEventEmitter(NativeModules.RNEventEmitter);
this.emitter.addListener("consolenotification", (data) => {
alert("consolenotification" + JSON.stringify(data));
});
So this is kind of a hacky solution, but it works
Edit: If your sending the notification from console and the app is killed https://github.com/wix/react-native-notifications/issues/326#issuecomment-507371366 might work, worked for me;
Although it does not work in one case:
App Killed -> Notification Received from the console -> App Opened via launcher -> Clicked on the notification
This does not do anything as the OnCreate event has already passed.
Currently, I ended up having a "pushNotification" key against a blank value in the Firebase Console's Additional Options, until I find a better way to do this. The purpose of the key is that the library takes some decisions based on this key and it just needs to to be present to satisfy a condition which was failing
@vishalambre could you please clarify how your workaround should be implemented for the case Killed/Background + FCM. I'm suffering from the problem initial notification is always undefined.
I'm not very familiar with Java, sorry.
I tried to add a method you've mentioned in MainActivity and subscribed with the js code. See nothing in a console.
@anisimov74 Same
@vishalambre Could you please elaborate (with a little more code)?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
I also see this issue. On Android, with the app in the background, and the notification sent through FCM, tapping the notification opens the app, but no event is raised. When the app is killed, it works, although getInitialNotification takes a _long_ time before it runs.
I'm facing with the same issue.
Currently, I can't reproduce that issue. sometimes the issue happened, sometimes it's not happened the issue can't reproduce totally.
I have the same issue, app in background - no event has been called. App killed - initial notification is getting called
If your sending the notification from console and the app is killed https://github.com/wix/react-native-notifications/issues/326#issuecomment-507371366 might work, worked for me;
Although it does not work in one case:
App Killed -> Notification Received from the console -> App Opened via launcher -> Clicked on the notification
This does not do anything as the OnCreate event has already passed.
Currently, I ended up having a "pushNotification" key against a blank value in the Firebase Console's Additional Options, until I find a better way to do this. The purpose of the key is that the library takes some decisions based on this key and it just needs to to be present to satisfy a condition which was failing
Edited the Original Answer too
@vishalambre could you please clarify how your workaround should be implemented for the case Killed/Background + FCM. I'm suffering from the problem initial notification is always undefined.
I'm not very familiar with Java, sorry.
I tried to add a method you've mentioned in MainActivity and subscribed with the js code. See nothing in a console.
Updated the reply with a proper work around
facing the same issue, any updates on this?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
The issue has been closed for inactivity.
Most helpful comment
Hi, I too had faced the same kind of issue so I am posting my findings here.
First we need to understand when the notification is received and where it's sent from as the behavior depends on both these aspects.
Now let's mix and match these cases and see from where we can get the payload:
registerNotificationOpenedregisterNotificationOpenedgetInitialNotificationNow why does this occur:
As per Handling Messages, the notifications that are generated using Admin SDK are received by this library code, whereas the notifications that are sent by the FCM console are received by the Firebase SDK and the notification is generated by it. Now in this case the data payload is delivered in the extras of the intent of your launcher Activity.
You can get this data from your launcher activity's; This can be verified using:
By adding this in your launcher activity; For the sake of simplicity the code considers a random timer of 10 seconds to allow the listener to be set otherwise the event will be emitted before the listener is attached, but you can get the data using some native method which gets called from the JS instead of this timer
)
And by adding this in your JS where you want the notification
So this is kind of a hacky solution, but it works
Edit: If your sending the notification from console and the app is killed https://github.com/wix/react-native-notifications/issues/326#issuecomment-507371366 might work, worked for me;
Although it does not work in one case:
App Killed -> Notification Received from the console -> App Opened via launcher -> Clicked on the notification
This does not do anything as the OnCreate event has already passed.
Currently, I ended up having a "pushNotification" key against a blank value in the Firebase Console's Additional Options, until I find a better way to do this. The purpose of the key is that the library takes some decisions based on this key and it just needs to to be present to satisfy a condition which was failing