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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo Push Notifications not received when app is closed [SDK 38.0.9] #9748

Closed
JamieS1211 opened this issue Aug 13, 2020 · 14 comments
Closed
Labels
needs validation Issue needs to be validated

Comments

@JamieS1211
Copy link
Contributor

馃悰 Bug Report

Summary of Issue

When sending push notifications (managed workflow) to android devices (running a built standalone app), using Expo push notification service, notifications are not delivered when app is closed. These notifications are delivered when the app is in the foreground or background .

Environment - output of expo diagnostics & the platform(s) you're targeting

Expo CLI 3.24.0 environment info:
System:
OS: Windows 10 10.0.18362
Binaries:
Node: 12.16.0 - C:\Program Files\nodejs\node.EXE
npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD
npmPackages:
expo: 38.0.9 => 38.0.9
react: 16.11.0 => 16.11.0
react-dom: 16.11.0 => 16.11.0
react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2

Reproducible Demo

app - https://github.com/JamieS1211/Expo-Notification-bug-app

Steps to Reproduce

  1. Install demo on android device using apk included in demo repo (https://github.com/JamieS1211/Expo-Notification-bug-app/blob/master/Builds/notification-demo-app-a329051fa10249ee9954446488fe7002-signed.apk) OR by:
    • Cloning demo
    • Build app using expo ba
    • Download freshly build apk
  2. Run app open app on phone and copy the expo push token and then close the app
  3. Copy expo push token into ExpoPushNotificationTool at https://expo.io/notifications
  4. Send a test notification using the ExpoPushNotificationTool

Expected Behavior vs Actual Behavior

I would expect a the notification to be received.

@JamieS1211 JamieS1211 added the needs validation Issue needs to be validated label Aug 13, 2020
@ghost
Copy link

ghost commented Aug 14, 2020

The same issue happens to my Huawei P30 Pro, notifications failed to arrive intermittently.
Expo SDK 38
Using the expo-notification package: ~0.3.3

My app.json

"android": {
  "googleServicesFile": "./google-services.json",
  "package": "amberelectric...",
  "versionCode": 50019,
  "permissions": [],
  "useNextNotificationsApi": true,
  ...
},
...
"notification": {
  "icon": "./assets/images/push_notification.png",
  "color": "#FFFFFF",
  "iosDisplayInForeground": true,
  "androidMode": "default"
}

@JamieS1211
Copy link
Contributor Author

@amber-pli is this dependant on app activity status (closed, background, foreground)? Also, is it working on other android devices? Everything is perfect on my iOS test device and android device provided the app is in the background or foreground. When on my android device and the app is closed the notification doesn't arrive 100% of the time.

@ghost
Copy link

ghost commented Aug 14, 2020

@JamieS1211 Mostly the same behaviour as yours (iOS iPhone SE and Android Huawei P30 Pro). With the android device, when the app is closed/killed the notification doesn't arrive 100% of the time.

In addition: when my app is in the foreground on android device, notification never arrive.

@JamieS1211
Copy link
Contributor Author

Does your notification on android arrive when app is in the background and do you use "nextNotificationAPI"? I had an issue because I forgot to add the code for the foreground listener.

Details here: https://docs.expo.io/versions/latest/sdk/notifications/#handling-incoming-notifications-when-the-app-is
image

@ghost
Copy link

ghost commented Aug 14, 2020

@JamieS1211 thanks I think I have missed setNotificationHandler, which should fix the foreground notification issue.

@JamieS1211
Copy link
Contributor Author

@amber-pli Glad I could help. Now I can welcome you to the club of notifications being fine except on android devices when the app is closed haha

@ghost
Copy link

ghost commented Aug 14, 2020

Refer to #5058

@ghost
Copy link

ghost commented Aug 14, 2020

@JamieS1211 Have you tried SKD38 with legacy notification?

@JamieS1211
Copy link
Contributor Author

@amber-pli Thanks for that other bug report, was an interesting read. I am indeed testing on a OnePlus device and suggested by the post. I have however just double checked and disabled "battery optimisation" for my test app and still no luck (also restarted the phone).

I haven't tried SDK38 with legacy notifications. I was having a large amount of problems before the SDK38 update with notifications, and actually had a draft bug report when I (ironically) got a google notification saying SDK 38 was released. As such I scrapped my bug report and adopted SDK38.

@JamieS1211
Copy link
Contributor Author

Having done more reading on the topic and gone through my settings for about 15 minutes I found a setting under "Settings" -> "System" -> "Recent app management" (OnePlus 3 device). By changing this settings to "Normal clear" I was able to receive notifications with the app closed.

image

I guess the logical next steps should be this:

  1. Give this a warning or disclaimer in the Expo push notification guide to acknowledge this can happen.
  2. Identify any programmatic solution that can be done in Expo or our apps.
  3. Work super hard to try and maintain a close to exhaustive list of the problematic settings on different devices

My personal thoughts on step 2

  • A programmatic way to detect the problematic setting and allow a user to press a button to automatically open settings to that point would be the best case scenario. I doubt this is possible to be honest.
  • A task that runs every 60 seconds, that reports the app's current status (foreground, background or closed). Should the app be in foreground or background, this task could schedule itself to occur again in another 60 seconds. This would mean that the service being reported to would be able to know if an app is closed and still running background code (would receive a "app closed" message) or it could infer the app is closed and NOT running background code should the regular status reports stop without a "app closed" message

@cruzach
Copy link
Contributor

cruzach commented Aug 18, 2020

@JamieS1211 I think since the Android OS tells the user that this setting may result in notifications not being delivered, if they select this, it's most likely because they are OK with notifications not being delivered (or don't want them delivered, in which case it would be unwise to try and work around that).

I'm not really sure what the task that runs every 60 seconds would be able to do about this setting, but if you'd like to try something like that out, I think expo-task-manager is what you're looking for.

Closing this since it's not a bug with the Expo SDK

@cruzach cruzach closed this as completed Aug 18, 2020
@JamieS1211
Copy link
Contributor Author

Hi @cruzach thanks for your message and link to "expo-task-manager", I will try and come up with a solution of my own here (others have suggested internal secondary receipts - probably a better idea).

In light of the fact many users configure their phone settings months to years before they may install any given app, and across different devices this could even be the default, I think it is at least worth mentioning it in the notification docs that this type of issue may occur. While your dead on that this isn't an expo bug (and having looked around people have issues with this all the time outside of expo), I think any message that could potentially save developers time and frustration, and by extend you guys from responding to tickets such as this, is a good thing.

I don't think I am by any means most qualified to write such a warning / info message for the docs but I will have a crack and make a PR to the docs. Worst case scenario someone comes up with better phrasing!

JamieS1211 added a commit to JamieS1211/expo that referenced this issue Aug 18, 2020
Added warning / information message about possible failure of message delivery with android devices dependant on aggressive battery optimisation settings from certain device manufacturers.

Related issues:
expo#9748
expo#5058

Informational articles:
https://www.freecodecamp.org/news/why-your-push-notifications-never-see-the-light-of-day-3fa297520793/
https://hackernoon.com/notifications-in-android-are-horribly-broken-b8dbec63f48a
cruzach added a commit that referenced this issue Aug 18, 2020
* Warning for possible android delivery failures

Added warning / information message about possible failure of message delivery with android devices dependant on aggressive battery optimisation settings from certain device manufacturers.

Related issues:
#9748
#5058

Informational articles:
https://www.freecodecamp.org/news/why-your-push-notifications-never-see-the-light-of-day-3fa297520793/
https://hackernoon.com/notifications-in-android-are-horribly-broken-b8dbec63f48a

* Update docs/pages/push-notifications/receiving-notifications.md

Co-authored-by: JamieS1211 <jamieshepherd1211@gmail.com>

Co-authored-by: Charlie Cruzan <35579283+cruzach@users.noreply.github.com>
@ghost
Copy link

ghost commented Aug 19, 2020

@JamieS1211 I thinks #9037 is related to our issue and fixed in #9287, which will be available in SDK 39

@JamieS1211
Copy link
Contributor Author

@amber-pli those are interesting. I uave not observed that behaviour myself but perhaps now some notifications are coming through I will get thos. Will keep my eyes out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs validation Issue needs to be validated
Projects
None yet
Development

No branches or pull requests

2 participants