notifee: Android: onForegroundEvent not listening to onPress Event
Hey, thanks for building such a cool package for handling notifications in RN.
The current issue that I’m facing is that, if the app is in the foreground state and I click on the notification. The onForegroundEvent is not listening to that action, and I’m unable to receive the notification payload or any event type, rather it gives the warning that the onBackgroundEvent is not setup.
The strange thing is that, when the notification is delivered. I’m able to get a log from the onForegroundEvent, for the Event type delivered, but on clicking the notification, nothing happens.
Info
"@notifee/react-native": "^7.2.0",
"react-native": "0.70.5",
"react": "18.2.0",
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
kotlinVersion = '1.7.10'
The current workaround, that I’m using is, which was suggested by @mikehardy .
Being, we store the notification in the onBackgroundEvent, in a global state management storage and then retrieve it, wherever in the app we require.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 42 (11 by maintainers)
Hey All, I’ve pushed a solution and a pre-release of v7.7.0-0.
npm i @notifee/react-native@7.7.0-0
I’ve left some notes on the p/r with a screen recording showing the final result. https://github.com/invertase/notifee/pull/720
I will not actually publish this as a final version until Monday which gives time for feedback.
Reopened issue for now until it’s in a final release.
still having this issue, i can listen DELIVERED event, but when i press the notification it does nothing
Closing issue as original issue is now fixed with pre-release
v7.7.0-0
. Will be released later today.for iOS, please use the notifee methods.
I tested this with the example app we have
packages/react-native/example
on Samsung S21 an it’s working on Android 13 and I believe it will be the same for Android 12 too. The app is on the latest react-native version… not sure if that makes a difference.If it is not crashing your app when it’s firing the foreground event when the app is active (even if visually it’s in the background), then I think that is fine. If you need to know if the app is in focus for a specific foreground event, you can use the
AppState
I really don’t like that it’s called
onForegroundEvent
as it is misleading. I think it should be called something likeonEventListener
which means if the app is “running” or “already launched”, the listener is still active.And, then the
onBackgroundEvent
should be when the app is truly closed and the app’s activity is not running.But this latest fix is to get the same original behaviour where background event can mean quit or in the background, and foreground event is when the app is in focus on the screen.
As I mentioned above, if you could provide a video or more details of how this negatively effects your app, that would be helpful.
Same issue here! Android 12. Only “delivered” event works. Issue still present in 7.6.1
The issue is still present in 7.8.2 on Android
@react-native-firebase/messaging 19.2.2 react-native 0.72.4 Android 14 (Emulator/Device)
Test case:
@k0502s please can you be more detailed? which platform and which type of notification? local (via notifee) or remote (via RNFB)?
@helenaford
The onBackgroundEvent method is not functioning in the background state even though v7.7.0-0 is using the setBackgroundMessageHandler.
@k0502s @MandeepKaur-1 please can you provide a screen recording?
Sometimes it may be still classed as “foreground” if the app is running but may visually be in the background. If you have just pushed it into the background without opening another app for example.
Have you checked out my video on the p/r https://github.com/invertase/notifee/pull/720. This shows when the background event is fired
What is the re-direction issue you are facing? Are you receiving a foreground event instead?
The issue is still present in 7.4.0
Me too. Having same problem. Can’t receive foreground event
I’m also facing the same problem, onForegroundEvent not getting fired when pressing on the notification on Android