Open edo1493 opened 8 years ago
GcmAndroid.addEventListener('notification', ...
gets triggered when your app is backgrounded, but doesn't have a valid notification object
Instead, you should be using
if (GcmAndroid.launchNotification) {
var notification = GcmAndroid.launchNotification;
console.log("Got notification while app asleep", notification);
Notification.create({
subject: notification.title,
message: notification.message,
});
GcmAndroid.stopService();
}
@pranaygp I can see the console.log("Hello") and that is the code they show for the GCMAndroid component. Further, if my adb logcat shows "ReactNativeJS: 'receive gcm notification'" and console logs its content, it means it gets triggered.
@edo1493 I just went over your issue again. I realize that I missed some stuff the first time I read it.
So, if your app is backgrounded (just hitting the home button doesn't do it, you need to close it completely) then the notification
event doesn't get triggered. Instead, you need to use the GcmAndroid.launchNotification
object globally in your index file (I provided an example of using it above).
If your app is in the foreground (open, or you only hit the home button (which only suspends the app)), you can use the function that you wrote above.
Now , in case your app is in the foreground, you want to remove this if statement if (!GcmAndroid.isInForeground) {
so that the notification actually get's sent out (That's how I got mine to work)
@pranaygp I don't think I explained myself very clearly.
If the app is in foreground, the notification event is able to catch it and a system sound is created with the create method. This is okay.
If I hit the home button (app is in background), the notifications event is able to catch the incoming notification, but the create method doesn't generate anything.
I am trying to solve the second issue.
@edo1493
Try removing the check for GcmAndroid.isInForeground
. That did the trick for me.
Also I should mention this: After your last comment, I checked my app again and upgraded it to use the latest version of this library. I'm having a similar issue too. I'd try using an older version of this (a release from last week or older)
@pranaygp As I have already mentioned, the problem is with the .create method. Everything goes through. I am not able to create the notification.
@edo1493 yeah, in that case, try reverting to a slightly older version. I believe the current build has an issue. I'm having the same thing.
If the app is completely closed, I get:
"undefined is not an object (evaluating RCTToastAndroid.SHORT)"
This is an issue I have already seen in GCMAndroid.
That sounds Ike an issue with RCTToastAndroid
I'd be happy to give your codebase a quick look if you want me to.
@pranaygp It's exactly as the example on https://github.com/oney/react-native-gcm-android
I don't see a reference to RCTToastAndroid on that example. That really could be what's causing your issue. I'd look into that.
Sorry for not being of much help. I'm still not able to recreate the issue you're having.
@edo1493 did you managed to solve this issue? You are experiencing this because GcmAndroid.addEventListener('notification', is not fired when the app is on background (as what i am experiencing too) . And now im stuck . Did you find a work around bout this issue? thanks
Hi team, background issue. Notification.addListener('press', function(e) { console.log(e); }); getting called when app running in foreground. But not when app is running in background. Someone help please. thanks in advance.
@Neson Do you have any thoughts on the discussion above?
@xphaul Sorry, I have seen this just now. No, I didn't solve it in the end and the project stopped there.
Hi, I am trying to use https://github.com/oney/react-native-gcm-android with this other component to receive Notifications on Android. However when the app is on the background, I am not able to display anything. I am posting my logcat and code.
The notification is received, but when I try to create it, I don't see anything. I wasn't adding the "small icon", so I thought it was failing for this reason. However, even after creating one, I am not getting anything.