React-native-notifications: [Android] Firebase doesn't work in Background.

Created on 4 Feb 2019  路  10Comments  路  Source: wix/react-native-notifications

In the last version of react-native-navigation. The background message doesn't pop up, unless I open the app.

I am checking the native implementation and I see that what it is missing is this chunk of code in the AndroidManifest.xml:

<service android:name=".FCMService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Which basically is a service. So basically my question is which services should I point out?

馃彋 stale

Most helpful comment

Oh and this is our full PR: https://github.com/kaloncheung124/react-native-notifications/pull/3. Most of it was merging in master I guess.

All 10 comments

@yogevbd

Hey @AugustoAleGon

I am currently in the process of updating from GCM -> FCM and I ran into the same behaviour.

Turns out it's related to how your server side sends the JSON payload.

https://firebase.google.com/docs/cloud-messaging/android/receive

Handle notification messages in a backgrounded app
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.
This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
For insight into message delivery to your app, see the FCM reporting dashboard, which records the number of messages sent and opened on iOS and Android devices, along with data for "impressions" (notifications seen by users) for Android apps.

@ItsNoHax were you able to get background notifications working without implementing that service?
@AugustoAleGon any updates?

We have the same problem - has anyone managed to get this working?

Let me give a brief overview about what I found @kaloncheung124 @llostris in my particular case I was testing FCM in a Xioami Redmi 5A which is a low class phone, not so much memory just 2GB of Ram. In the process of Push Notifications I found that my process on Background was always closed by the memory manager of the phone. I found this using https://github.com/vikeri/react-native-background-job for background process because I didn't to complicate more using a Headless JS services.
So when I tested on the emulator the app even if I killed, did receive the notification.
At the end I didn't keep the background services, in my perspective it was too much memory for something that is already being handle by the native code.

We eventually got it working. My coworker figured it out. I'm not sure exactly what it took but here is my fork that we're using: https://github.com/kaloncheung124/react-native-notifications

More specifically: This is probably the commit that fixed it: https://github.com/kaloncheung124/react-native-notifications/commit/494aa9214a98c07ee5d6d11f7918dfad2efbe0ed. I think my fork has diverged a little from master though.

@kaloncheung124 thanks for sharing. Appreciate it.

Oh and this is our full PR: https://github.com/kaloncheung124/react-native-notifications/pull/3. Most of it was merging in master I guess.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

As @ItsNoHax mentioned, it related to how you send the notification payload.
https://firebase.google.com/docs/cloud-messaging/android/receive

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josefheld picture josefheld  路  4Comments

Lastin picture Lastin  路  5Comments

denissb picture denissb  路  5Comments

Mimble-Wimble picture Mimble-Wimble  路  3Comments

beulahpt picture beulahpt  路  5Comments