Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

onNotification does not fire when received on Android #170

Closed
JonesN3 opened this issue Aug 23, 2016 · 25 comments
Closed

onNotification does not fire when received on Android #170

JonesN3 opened this issue Aug 23, 2016 · 25 comments

Comments

@JonesN3
Copy link

JonesN3 commented Aug 23, 2016

Is this feature not supported on android, or am I doing something wrong?

@heminm
Copy link

heminm commented Aug 25, 2016

What version of the package and RN are you using? Are you trying local or remote notification?

@JonesN3
Copy link
Author

JonesN3 commented Aug 31, 2016

RN 30, local notifications.

@vikeri
Copy link

vikeri commented Sep 13, 2016

I have the same issue with local notifications, when I schedule one and it fires onNotification is not triggered. But if I click the notification it is.

@barroslee
Copy link

I got same issue with local notifications and RN 0.33.0. onNotification() is not called until I click the notification. I just add notifyNotification() in sendNotification() for a temporarily solution....

@npomfret
Copy link
Contributor

So the previous behaviour was for onNotification() to be called immediately after sending a local (or scheduled) notification?

Does this only affect Android?

Has it started happening since RN 0.33?

@vikeri
Copy link

vikeri commented Sep 19, 2016

It never worked for me. I added this library around 0.31.0 only doing Android for now though. Looked through the Java code but could not find any callback to JS in the code that runs when the notification is fired.

@vikeri
Copy link

vikeri commented Sep 19, 2016

i.e. I'm not sure it ever worked as @npomfret describes

@npomfret
Copy link
Contributor

Sorry, I was just asking a question. In order to fix it I need to know what is the desired / expected behaviour for receipt of a local notification? What does the iOS implementation do?

@barroslee
Copy link

barroslee commented Sep 19, 2016

Hi @npomfret , I am not sure what's the real behavior. Just because I click the notification, onNewIntent() will be called. then notifyNotification() will fire event 'remoteNotificationReceived' to trigger onNotification. So I add it in sendNotification().

In ios when app is foreground, the notification never appear but just trigger onNotification.

I upgrade to RN 0.33 from RN 0.30. Both of them have this issue.

@npomfret
Copy link
Contributor

Ok, I think the answer to the question "what should the behaviour be?" is the same as iOS, right?

I think the iOS behaviour is this:

  1. Send a local notification while app is in the background -> the notification appears in the notification centre but onNotification is not called.

  2. Send a local notification while app is in the foreground -> the notification does not appear in the notification centre but onNotification is called.

  3. Click on an alert in the notification centre when the app is in background -> onNotification is called.

Does that sound correct?

@mcmatan
Copy link

mcmatan commented Dec 25, 2016

@npomfret Yes, you are correct that is the way is works on IOS, and I really wish it would be the same on android (:

@avdept
Copy link

avdept commented May 23, 2017

Any progress on this? Not getting onNotification called while app in foreground on android

@pawlowskim
Copy link

Same issue. "onNotification" is not called on Android when notification arrives (only shows in notification center). After clicking the notification "onNotification" is triggered (but in that case, alert I want to display isn't showing because application can be in inactive state probably, when I added delay it start working).

@kesha-antonov
Copy link

Hello guys! @npomfret
Did you find time to fix it?

@pawlowskim
Copy link

We do some tests. We make a fork and implement notification to show in notification center only if application is in background. If application is in foreground we dispatch event to JS that arrives in "onNotification" from PushNotification.configure object (works the way it works on iOS). On both events we show alert. Now we can say, that alert triggered from notification in both cases not shows every time. We don't know why yet and I can't guarantee we gonna investigate it.

You can test this fork https://github.com/MateuszMxxxx/react-native-push-notification but the code might not work correctly in every case (lack of native skill :/ ). We gonna make PR for this fork in the future.

@nonameolsson
Copy link

nonameolsson commented Sep 7, 2017

Hi! I have been struggling with this strange problem for a couple of hours before finding this issue. I'm not sure what the current status on this is? And I'm not sure it's the same problem I have. I will describe my problem, and maybe you could guide me on how to solve it?

The function called onNotification has following instructions in the documentation: // (required) Called when a remote or local notification is opened or received.
When a notification is showing and I press it this callback is triggered. But if I don’t do anything then it’s never triggered.

As I understand it, this callback should be triggered whenever a notification is triggered, right? And the only thing that should change is notification.userInteration?

What I need to do is when a notification is showed I need to dispatch an action to remove stuff from my Redux store. So this is the callback I should be using, right?

Here is a video showing my problem: https://youtu.be/NwcBsameqQ0

@nazywamsiepawel
Copy link

Any progress on this? Is the onNotification not called on purpose?

@gpopovic
Copy link

Any progress?

@ital0
Copy link

ital0 commented Oct 31, 2017

btw, there's a PR waiting for aproval. For me now fires onNotification (tested only in foreground).

@butterfly-thomasdittmar

My app is sitting in Beta (Google Play Console) for over 2 months now.

Everything is working fine in iOS. I get remote PN and it wakes up the app, redirects the router to the correct page because onNotification() gets called in iOS every time (app closed, app open in background and app in foreground).

Unfortunately onNotification() only gets called on Android when the app is in foreground.

I really hope this issue gets resolved soon. BTW @ital0 the PR you are referring to does not resolve the problem when the app is closed and in the background. I have really tried every solution available in the issue section without success.

"react": "16.0.0-alpha.6",
"react-native": "^0.44.0",
"react-native-push-notification": "^3.0.1"

@ital0
Copy link

ital0 commented Nov 14, 2017

@butterfly-thomasdittmar PR works for me, even when app is closed. Strange that doesn't works for you.
When app is closed, the notification came a little different that when app is in foreground.

@ErikMikkelson
Copy link

ErikMikkelson commented Nov 14, 2017

@ital0, I updated that PR because I noticed that the userInteraction flag was overridden to false. Also @butterfly-thomasdittmar, @iggyfisk's solution from 122 worked for me. Once I added android.intent.category.INFO, it went to the right place.

I can receive (local)notifications in the foreground and background on iOS and in the foreground and background (cold and warm start) on Android with Android firing the onNotification event. I'm not sure how much of this is bubble gum and bailing wire. Also, the app I'm coding for is using react-native-navigation that has both a splash screen and switches between single and tab-based app, so that added a bunch of other headaches. I haven't verified remote notifications as the app doesn't use them yet. It's still pretty finicky.

@nonameolsson
Copy link

So, there is a PR fixing this issue? But it doesn't get merged? How so?

@Gp2mv3 Gp2mv3 closed this as completed Jul 4, 2018
@NikhilP99
Copy link

In my case, it is not working even when clicked on the notification. onNotification is bever called.
RN 0.59.4

@Adr1ann
Copy link

Adr1ann commented Jan 9, 2020

Any solution? Still not working...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests