Skip to content

Unable to prevent data-only Background notifications from displaying a notification (Android) #684

Description

@tdous

Using v.3.2.2 of RNN, and react-native 0.63. Didn't want to upgrade as right at the end of a build and don't want to switch version unnecessarily just yet.

We send pushes to display notifications for users, but also data-only notifications to trigger updates behind the scenes. I don't seem to be able to stop blank notifications from showing up in the notification tray. By which I mean the icon and app name, with no content (because there isn't any content to display).

Like this

I'm a little confused by a combination of the docs not mentioning much about the completion callback, and another Github issue that suggested the completion function is not correctly documented, so I might be missing something, or misusing that somehow...

The notification payload arriving via FCM looks like this:

{
  from: "XXXXXXXXXXXXX",
  google.c.sender.id: "XXXXXXXXXXXXX",
  google.delivered_priority: "normal",
  google.message_id: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  google.original_priority: "normal",
  google.sent_time: 1234567890000,
  google.ttl: 1234567,
  show: "false", // A setting which is used in the foreground, should be ignored in the background
  type: "update", // For filtering the type in the listener above
  action: "SOME_ACTION", // A sub-type, an action to trigger when in the foreground
}

And my listener looks something like this:

Notifications.events().registerNotificationReceivedBackground((
  notification: Notification,
  completion: (response: NotificationCompletion) => void
) => {
  switch (notification.payload.type) {
    // Some alert type to display in background
    case 'SOME_ALERT':
      completion({ alert: true, sound: true, badge: true });
      break;

    // Another type of alert to display
    case 'ANOTHER_ALERT_TYPE':
      // Maybe do something else here and then...
      completion({ alert: true, sound: true, badge: true });
      break;
    
    // THE PROBLEM - I have tried filtering this type, and different
    // formats of completion function, and also just leaving this
    // entire case out entirely, but the notification is always shown.
    case 'update':
      completion({ alert: false, sound: false, badge: false });
      // OR... completion(); - or no args, unclear what this does
      // OR... Something else to stop notifications from appearing??
      break;
  }
});

This is all going fine in the foreground, and the background notifications I do want to display are ok too. I'm just probably missing something obvious about how to handle (in my case ignore) these "hidden" pushes in the background. If anyone can point to my mistake or misunderstanding I'd be very grateful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions