react-native-push-notification: Notification popup not showing when app at background - Android
Bug
Remote notification doesn’t pop up on Android when app is in background. I did receive the notification at onNotification though. Side note: Notification pop up was working back in version 3.2.1. At that time, both notifications from firebase console and my own api will trigger onNotification and show popup. However with the current version, using firebase console will show the notification in notification tray but doesn’t popup nor trigger onNotification while using my api will trigger onNotification but does not show popup.
Environment info
react-native info
output:
System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
Memory: 39.16 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 13.7.0 - /usr/local/bin/node
Yarn: 1.17.0 - /usr/local/bin/yarn
npm: 6.14.2 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
Android NDK: 20.0.5594570
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
@react-native-community/cli: ^2.9.0 => 2.10.0
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5
npmGlobalPackages:
react-native-cli: 2.0.1
Library version: 3.4.0
Steps To Reproduce
- Install & setup react-native-push-notification
- Use Firebase console to send test message = Notification popup showed but onNotification not triggered
- Use own api to send notification = Notification popup not showed but onNotification triggered
Describe what you expected to happen:
- Notification pop up when app is in background/exit
Reproducible sample code
- npm i --save react-native-push-notification@3.4.0
- Set up androidmanifest.xml and gradle file as per instruction
- Set up code as follow:
PushNotification.configure({
onRegister: function (token) {
console.log("TOKEN:", token);
},
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log("NOTIFICATION:", notification);
// process the notification here
// required on iOS only
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
// Android only
senderID: "XXXXXX", //This is hidden to protect my own project
// iOS only
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true
})
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 17
And what is the message send from server-side:
@muriloneo having same issue notification sounds and pops up when app in foreground but when app closed or background notification silently show icon on notification tray (or area where notification icon show). how to implement same function for all states like social media messenger do. @Dallas62 if you have solution kindly spare some kind time
I can’t get pop up to show on background.
Replicated all example code, might be missing something.
AndroidManifest.xml
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" /> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" /> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>android/app/build.gradle
implementation 'com.google.firebase:firebase-analytics:17.3.0' implementation project(':react-native-push-notification')
android/build.gradle
classpath("com.android.tools.build:gradle:3.5.3") classpath('com.google.gms:google-services:4.3.3')
What is missing?
Yea I did, it didn’t work. It shouldn’t be implementation issue right? Because back in v3.2.1, everything was working fine with my current implementation
Basically if I send notification from firebase console:
If I send notification from my server:
Edit: Both type of notification did trigger messaging().setBackgroundMessageHandler() though
Hi @Gabsys Make sure you are on the latest version, Also note this issue might be related to the version
3.2.1
, the default channel is set to a wrong priority. Two solutions: