react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

onNotification does not fire when received on Android

Open jonesn3 opened this issue 10 years ago • 25 comments

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

jonesn3 avatar Aug 23 '16 13:08 jonesn3

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

heminm avatar Aug 25 '16 17:08 heminm

RN 30, local notifications.

jonesn3 avatar Aug 31 '16 18:08 jonesn3

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.

vikeri avatar Sep 13 '16 13:09 vikeri

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....

barroslee avatar Sep 18 '16 16:09 barroslee

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?

npomfret avatar Sep 18 '16 18:09 npomfret

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 avatar Sep 19 '16 05:09 vikeri

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

vikeri avatar Sep 19 '16 05:09 vikeri

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?

npomfret avatar Sep 19 '16 08:09 npomfret

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.

barroslee avatar Sep 19 '16 09:09 barroslee

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?

npomfret avatar Sep 19 '16 10:09 npomfret

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

mcmatan avatar Dec 25 '16 20:12 mcmatan

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

avdept avatar May 23 '17 12:05 avdept

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).

pawlowskim avatar Jun 26 '17 10:06 pawlowskim

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

kesha-antonov avatar Aug 01 '17 12:08 kesha-antonov

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.

pawlowskim avatar Aug 07 '17 12:08 pawlowskim

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

nonameolsson avatar Sep 07 '17 03:09 nonameolsson

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

nazywamsiepawel avatar Sep 07 '17 11:09 nazywamsiepawel

Any progress?

ghost avatar Oct 26 '17 10:10 ghost

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

ital0 avatar Oct 31 '17 11:10 ital0

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"

butterfly-thomasdittmar avatar Nov 14 '17 03:11 butterfly-thomasdittmar