React-native-push-notification: Android did not receive remote notifications when app is in foreground

Created on 8 Jun 2020  路  8Comments  路  Source: zo0r/react-native-push-notification

Bug

App is not receiving any remote notifications when app is in foreground state. Background remote notifications are working correctly.

I've also set this to true in manifest file:

<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                    android:value="true"/>

Environment info

react-native info output:

System:
    OS: Windows 10 10.0.18363
    CPU: (4) x64 Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz
    Memory: 1.22 GB / 7.88 GB
  Binaries:
    Node: 12.9.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.10.2 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0
      System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 1.8.0_221 - C:\Program Files\Java\jdk1.8.0_221\bin\javac.EXE
    Python: 2.7.16 - C:\Python27\python.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0
    react-native: 0.62.2 => 0.62.2
  npmGlobalPackages:
    *react-native*: Not Found

Library version: 3.5.2

Steps To Reproduce

  1. Install app on real device
  2. Get device token and send test message from firebase while app is in foreground
    ...

Describe what you expected to happen:

  1. App should receive notification even in foreground if we specify the line in manifest

Ps. I'm using the example app for now, so the configs are same

Most helpful comment

Hello @theasc
Thank you for pointing that out, somehow I missed that. Sorry @Dallas62 for taking your time on this.
Thanks for your great work!

All 8 comments

Hi @iarmankhan
I just test this, and this is working well, maybe a cache problem with gradle ?

I am observing exactly the same issue but with Android emulator.

My steps:

  1. Run an app in the emulator
  2. Get device token
  3. Use the token to send a notification via firebase console
  4. onNotification is not triggered while the app is in foreground.

Hello @Dallas62

Well if it was a cache issue it should be solved by now, because after posting this issue here I built app multiple times and tested but it's still same.

I also tried it with released app (made using --variant=release) and it's same in that too.

EDIT : I'm talking about remote notifications (sent from firebase or server) for local notification it's working correctly (I did not use local notification in my app but it was working on example app)

Hi @iarmankhan @apalchys

I would be pleased to help you, but I did the exact same test as @apalchys, and all is working as expected...

If appstate == foreground && com.dieam.reactnativepushnotification.notification_foreground == true

  • The notification is displayed and onNotification is triggered.

If appstate == foreground && com.dieam.reactnativepushnotification.notification_foreground == false

  • The notification is NOT displayed and onNotification is triggered.

Maybe I don't understand the issue, do you have more information like the content of the payload or the full step to reproduce with example project ?

I do all tests for issues on example project.

I have the exact same issue, here is my manifest



<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission tools:node="remove" android:name="android.permission.READ_PHONE_STATE" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application>
    <activity
        android:name=".MainActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:fitsSystemWindows="true"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustPan"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
        android:value="true"/>
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
        android:value="Example-Channel"/>
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
        android:value="Super channel description"/>
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
        android:resource="@android:color/white"/>

</application>

Hi @theasc

"Having the same issue" is not helping to resolve this.

Can you provide a reproducible example ? Or a complete description on what is working and what is not working.
As I said previously, I tried to reproduce this and all work as expected.

Hi @Dallas62, It works now I was just missing the following part:
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="false" > <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

Hello @theasc
Thank you for pointing that out, somehow I missed that. Sorry @Dallas62 for taking your time on this.
Thanks for your great work!

Was this page helpful?
0 / 5 - 0 ratings