---
# System prepended metadata

title: 'Backgrounded Android push notifications - Wed 11th Nov, 2020'
tags: [C+, android, backgrounded, programmingjournal, pushnotifications, '2020']

---

# Backgrounded Android push notifications - Wed 11th Nov, 2020

There was an issue with C+ Android push notifications. The app was receiving them and processing them while open (ie "foregrounded"), but nothing was happening when the app was closed (ie. "backgrounded") or shut down.

I did some digging into the native logs after triggering a push notificatin server side.

Grepping `adb logcat` for `RNPushNotification` revealed the following:

```
Cannot send to notification centre because there is no 'message' field
```

The issue is that my server-side setup is using the [legacy HTTP notification payload protocol](https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support). As such, Android and/or the library I'm using (react-native-push-notifications) is treating the notification as a [data message](https://firebase.google.com/docs/cloud-messaging/concept-options), so is not displaying anything to the user.

I do not want to change server-side implentation at this moment, so a workaround I have found is to trigger a "local" notification on push notification received and pass in the correct payload, resulting in a notification being displayed to the user.

```typescript=
if (!notification.userInteraction) {
    PushNotification.localNotification({
        channelId: ANDROID_CHANNEL_ID,
        ignoreInForeground: true, // show our own message in foreground
        ...notification.data,
        message: data.title,
        title: NOTIFICATION_TITLE,
    })
}
```

Some helpful links:
https://github.com/zo0r/react-native-push-notification/issues/1452
https://github.com/zo0r/react-native-push-notification/issues/1661

###### tags: `programmingjournal` `2020` `C+` `pushnotifications` `android` `backgrounded`