question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to prevent app from coming to foreground on notification action click

See original GitHub issue

In a Headless.js task I trigger a localPushNotification with notification actions.

PushNotification.localNotification({
  title: REQUEST_TITLE,
  message: REQUEST_MESSAGE,   
  playSound: false,
  soundName: "default",
  actions: '["Yes", "No"]',
});

I configured the handling this way:

PushNotification.configure({
    onNotification: handleNotificationClick
});

PushNotification.registerNotificationActions(["Yes", "No"]);

DeviceEventEmitter.addListener('notificationActionReceived', (event) => {
  console.log("Received notification action event" + JSON.stringify(event));
});

When the app is in background and I click one of the notification actions, the application is launched and brought to foreground. The onNotification handler is called, the DeviceEventEmitter.addListener callback is not called.

Does anyone know how to solve this issue? I want to handle the notification action click without bringing the application to the foreground. The configuration of the push notifications is executed in the componentWillMount method in App.js.

My setup is:

  • react-native: 0.59.5
  • react-native-push-notifications: 3.1.9

Thanks in advance!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:57

github_iconTop GitHub Comments

4reactions
mathiasmoellercommented, Jun 4, 2020

So far it seems to work like a glove! I also like the new way of handling the actions. Good work! I will let you know if I find any issues or bugs.

I strongly believe that Open Source Development should be supported more. If you are the new maintainer of this project @Dallas62 and enable Sponsoring for this repo I will be happy to show my support and gratitude 😃

1reaction
waryiarcommented, Aug 20, 2021

@Dallas62 Hi! Is it possible to prevent app invocation on action press on iOS?

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Hide notification from Foreground Service on click ...
You have to use .setOngoing(false) to dismiss the notification. Share.
Read more >
Handling Notifications and Notification-Related Actions
Tapping one of the buttons forwards the selected action to your app, without bringing the app to the foreground. If your app supports...
Read more >
Receiving Notifications - Expo Documentation
On Android, users can set certain OS-level settings (usually revolving around performance and battery optimisation), that can prevent notifications from being ...
Read more >
App notification content - Windows apps | Microsoft Learn
Using a selection menu and two buttons, we can create a reminder notification that utilizes the system snooze and dismiss actions. Make sure...
Read more >
[Cloud Messaging Plugin (Firebase)] App doesn't open on ...
When we click on the notification then app opens when in background but when is in foreground and the user gets push notification...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found