Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tdous opened this issue Oct 7, 2020 · 14 comments

Comments

@tdous
Copy link

tdous commented Oct 7, 2020

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.

@tdous tdous changed the title Unable to prevent background pushes from displaying a notification (Android) Unable to prevent silent/hidden Background pushes from displaying a notification (Android) Oct 7, 2020
@tdous tdous changed the title Unable to prevent silent/hidden Background pushes from displaying a notification (Android) Unable to prevent data-only Background notifications from displaying a notification (Android) Oct 9, 2020
@tdous
Copy link
Author

tdous commented Oct 9, 2020

I couldn't find clarity on this myself, and since I built our backend push sending service a couple of years ago I wondered if it was sending stuff in a way that was triggering these incorrectly. However I've since switched over to react-native-firebase which is handling them as expected (ie. not displaying anything) so I'm happy there's no issue there. So while this is not closed as far as understanding why it was happening, it's closed for me as I'm not longer using this module. I'll just leave this in case anyone else has the problem and someone else can clarify for them.

@stale
Copy link

stale bot commented Dec 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Dec 2, 2020
@mslipenchuk267
Copy link

not stale, Having the same issue

@stale stale bot removed the 🏚 stale label Dec 7, 2020
@menasSawwaf
Copy link

I have the same issue any update about this ??

@Plitzer
Copy link

Plitzer commented Jan 4, 2021

Also the same issue, this is very problematic when using data-only notifications.
To add to this issue, if you specify the usual notification payload keys (title, body, ...) INSIDE the data payload, they will be picked up by the 'blank' notification as if it were a part of the notification payload.

e.g. setting the title to 'Hello' and the body to 'World' in the data payload will present a notification that says
Hello
World

@stale
Copy link

stale bot commented Feb 3, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Feb 3, 2021
@erkie
Copy link
Contributor

erkie commented Feb 9, 2021

go away stolebot

@stale stale bot removed the 🏚 stale label Feb 9, 2021
@stale
Copy link

stale bot commented Mar 11, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Mar 11, 2021
@mp8446
Copy link

mp8446 commented Mar 14, 2021

Somebody found a solution for this?

@stale stale bot removed the 🏚 stale label Mar 14, 2021
@erkie
Copy link
Contributor

erkie commented Mar 14, 2021

I'm guessing it should be a pretty easy fix to just add an if-statement on this line, to not present empty notifications?

https://github.com/wix/react-native-notifications/blob/master/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java#L151

@stale
Copy link

stale bot commented Apr 14, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Apr 14, 2021
@erkie
Copy link
Contributor

erkie commented Apr 15, 2021

stalebot unstale!

@stale stale bot removed the 🏚 stale label Apr 15, 2021
@stale
Copy link

stale bot commented May 27, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label May 27, 2021
@stale
Copy link

stale bot commented Jun 3, 2021

The issue has been closed for inactivity.

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

No branches or pull requests

6 participants