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.

I don't receive notifications in background

See original GitHub issue

I want to have scheduled notifications that would push even when the app is killed. This is Settings.js where the user can schedule the notification:

async function onCreateTriggerNotification() {
    const date = new Date(Date.now());
    date.setHours(11);
    date.setMinutes(13);

    const trigger: TimestampTrigger = {
      type: TriggerType.TIMESTAMP,
      timestamp: date.getTime(),
  
    };

  await notifee.createTriggerNotification(
    {
      id: '123',
      title: 'Meeting with Jane',
      body: 'Today at 11:20am',
      android: {
        channelId: 'your-channel-id',
         pressAction: {
  launchActivity: "default",
  id: "default",
}
      },
     
    },
    trigger,
  );
}

index.js

notifee.onBackgroundEvent(async ({ type, detail }) => {
  const { notification, pressAction } = detail;
  if (type === EventType.ACTION_PRESS && pressAction.id === 'mark-as-read') {
console.log(notification)
  //  await notifee.cancelNotification(notification.id);
  }
});

App.js

async function bootstrap() {
   const initialNotification = await notifee.getInitialNotification();

   if (initialNotification) {
     console.log('Notification caused application to open', initialNotification.notification);
     console.log('Press action used to open the app', initialNotification.pressAction);
   }
 }

 useEffect(() => {
   bootstrap()
 }, []);

I can get a notification when the app is minimized but I don’t receive anything when the app is killed. I receive that notification only when I open the app again.

I’m new to this and a bit confused. Should I use something else like firebase messaging to be able to receive notifications even when the app is quit?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xenia19commented, Dec 8, 2021

@helenaford , it worked! Thank you so much! Thank you both for such a quick reply. You’re the best 😃

1reaction
helenafordcommented, Dec 8, 2021

@xenia19 have you tried creating a trigger with the following props (docs):

 alarmManager: {
    allowWhileIdle: true,
  }

@mikehardy I think we need to update the lib to default to using the alarm manager as I feel like it’ll be a lot easier, fewer steps to setup triggers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Notifications Not Showing Up? 10 Fixes You Can Try
Not seeing notifications show up on your Android phone? Try these fixes to get Android notifications working again.
Read more >
Why don't I receive notifications or sound alerts? - Email
Ensure that you have "Allow Notifications" enabled ; Go back to the home screen of your Settings app; Tap on "General"; Tap on...
Read more >
What can I do if I'm not getting any notifications on Android?
Go to Phone Settings > Apps > Wire > Data usage and check whether your phone is restricting background data for Wire. 5....
Read more >
Notifications Not Shown - Mobile Push
Common reasons why Mobile Push notifications are not showing on your device.
Read more >
IOS 14.2 iPhone 10X notifications not pre… - Apple Community
It may be that those apps are not running in the background as they ... I still get notifications for non Outlook email,...
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