notifee icon indicating copy to clipboard operation
notifee copied to clipboard

Query Android 13 onBackgroundEvent vs getInitialNotification

Open dorisaward opened this issue 1 year ago • 28 comments

I have an android 10 device and an android 13 device.

When the app is exited on the android 10 device and a notification is pressed, onBackgroundEvent handles the notification correctly. However, on the android 13 device, onBackgroundEvent doesn't pick up the notification. Only getInitialNotification works. If I implement both there are issues on android 10 as the notification is being handled twice. Is this how notifee is supposed to be working? The documentation makes it appear that getInitialNotification should not be required in my case.

dorisaward avatar Sep 08 '23 12:09 dorisaward

If I implement both there are issues on android 10 as the notification is being handled twice.

Hi! You can use Platform.Version to avoid double handling https://reactnative.dev/docs/platform For downvoters: This is just workaround. I totally agree, that the documentation should preferably be more complete.

pavelustenko avatar Sep 15 '23 08:09 pavelustenko

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Oct 26 '23 12:10 github-actions[bot]

We noticed some android 12 or 13 devices can trigger onBackgroundEvent when launching the app from a notification, but some cannot. It's unclear what the difference between them yet.

Yupeng-li avatar Nov 02 '23 16:11 Yupeng-li

Same situation, any ideas? I saw for sure it is not working for me on android 13 Samsung's devices ie Galaxy S23. To reproduce: I have active app, I'm sending firebase notification, I'm killing app and click notification. App is opening but onBackgroundEvent is not running so not able to interact somehow

Darex1991 avatar Nov 07 '23 15:11 Darex1991

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Dec 05 '23 16:12 github-actions[bot]

Not stale

liamjones avatar Dec 08 '23 09:12 liamjones

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Jan 05 '24 10:01 github-actions[bot]

Not stale

liamjones avatar Jan 05 '24 10:01 liamjones

Indeed - hopefully I'm able to reward your faith in this repo with some solid maintenance, it's a struggle but I am here and watching

mikehardy avatar Jan 06 '24 20:01 mikehardy

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Feb 03 '24 21:02 github-actions[bot]

Not stale

liamjones avatar Feb 05 '24 13:02 liamjones

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Mar 04 '24 14:03 github-actions[bot]

Not stale

liamjones avatar Mar 04 '24 15:03 liamjones

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Apr 01 '24 16:04 github-actions[bot]

Not stale

liamjones avatar Apr 02 '24 07:04 liamjones

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Apr 30 '24 09:04 github-actions[bot]

Not stale

liamjones avatar Apr 30 '24 09:04 liamjones

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar May 28 '24 10:05 github-actions[bot]

Not stale

Yupeng-li avatar May 29 '24 13:05 Yupeng-li

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Jun 26 '24 14:06 github-actions[bot]

Not stale

Yupeng-li avatar Jun 26 '24 15:06 Yupeng-li

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Jul 24 '24 15:07 github-actions[bot]

Not stale

Yupeng-li avatar Jul 25 '24 10:07 Yupeng-li

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Aug 22 '24 10:08 github-actions[bot]

Not stale

liamjones avatar Aug 30 '24 15:08 liamjones

I was wondering about this; after Android 12, onBackgroundEvent won't receive events when app was killed. I don't know why, but it does. so let's just say answer first: you should filter onBackgroundEvent and use getInitialNotification. (note: getInitialNotification returns same data when you do hot-reload.)

this comment (https://github.com/invertase/notifee/issues/616#issuecomment-1368171057) says onForegroundEvent, but I'm not sure It's working. in my device, I can only receive data from getInitialNotification. really confusing.

We noticed some android 12 or 13 devices can trigger onBackgroundEvent when launching the app from a notification, but some cannot. It's unclear what the difference between them yet.

check https://github.com/invertase/notifee/issues/621#issuecomment-2342711032. If some devices can fire event, but some others not, you can suspect reactContext might be null.

Eclipses-Saros avatar Sep 13 '24 05:09 Eclipses-Saros

Hi @Eclipses-Saros, thanks for the heads up. The first comment you shared is about iOS. On android, when you launch the app (app was closed), the onForegroundEvent will not fire.

We run the same app on different devices, but they have different behaviours. Is it possible that reactContext is null on some devices but not on others?

Yupeng-li avatar Sep 13 '24 08:09 Yupeng-li

okay, I'll make the answer more clearly:

"reactContext is null" problem is you cannot receive any notification events whether foreground or background. because reactContext is null, native library cannot emit events and nothing happened at all. however, I'm not sure notification from killed (exited) status also emit background event. and as far as I know, getting notification data when app was killed is a different.

The first comment you shared is about iOS. On android, when you launch the app (app was closed), the onForegroundEvent will not fire.

I remember notifee fires onBackground event when you press the notification at the app was closed; (https://notifee.app/react-native/docs/events#background-events) but looks like now it's no longer do it. (I'm not sure, but at least my android devices won't send any background events when it's killed)

If you want to receive data from onBackground event but some devices won't do this, reactContext might be a problem. you should check context exist first. also, double-check permission and policy settings to make sure it's working.

If not (just want to receive notification data on boot), try to use notifee.getInitialNotification(). it should be there. I'm currently check all initial notifications from firebase messaging and notifee.

const firebaseNotification = await messaging().getInitialNotification();
const notifeeNotification = await notifee.getInitialNotification();

(if there is NO data exists, then that is an another problem)

Is it possible that reactContext is null on some devices but not on others?

well... yes. I have two Android devices, which versions are 12 and 14. both are have same problem: reactContext is null. but once I tested someone's device, there is no problem. weird.

Eclipses-Saros avatar Sep 13 '24 09:09 Eclipses-Saros