Notifications not received on closed Android app (SDK 39/40)

Please provide the following:

  1. SDK Version: 39.0.3 and 40.0.0
  2. Platforms(Android/iOS/web/all): Android

I setup expo notifications on my app using the managed workflow.

Everything works fine on iOS, but nothing is received when the app is closed. However, the sent notification arrives lately after app re-opening.

To be clear:

  • When the app is open and in foreground: Works
  • When the app is open but in background: Works
  • When the app is closed (swipe out): Not working.

I did not have any luck digging on the documentation and the forums, except a 2 years old response of the expo team telling that it should work out of the box: Push notifications not working when app is closed

I also read a lot of notifications bug fix on Expo 40, so I will manage the upgrade soon, but nothing that seems related to my issue.

EDIT: I did the update to Expo v40. This do not resolve the issue.

I may provide more information if you ask, but as I don’t even know where to start, I would welcome even some clues or question! :slight_smile:

Thanks

1 Like

Hi!

Have you set the priority on the android notification channel (and the notification itself) to “high”?

Hi and thanks for the answer.

I think I did but I will test again.

However, I saw that Android notifications are not sent to the default channel, but the misc one:

But I did put the code line to set the notification channel:

const registerForPushNotificationsAsync = async (): Promise<string> => {
  const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
  let finalStatus = existingStatus;
  if (existingStatus !== 'granted') {
    const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
    finalStatus = status;
  }
  if (finalStatus !== 'granted') {
    throw new Error('Failed to get push token for push notification!');
  }

  if (Platform.OS === 'android') {
    Notifications.setNotificationChannelAsync('default', {
      name: 'default',
      importance: Notifications.AndroidImportance.DEFAULT,
    });
  }

  return (await Notifications.getExpoPushTokenAsync()).data;
};

Am I missing something here?

So I changed the default priority on my app:

diff --git a/src/index.tsx b/src/index.tsx
index 484f171..dfd4af4 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -39,7 +39,7 @@ const registerForPushNotificationsAsync = async (): Promise<string> => {
   if (Platform.OS === 'android') {
     Notifications.setNotificationChannelAsync('default', {
       name: 'default',
-      importance: Notifications.AndroidImportance.DEFAULT,
+      importance: Notifications.AndroidImportance.HIGH,
     });
   }

And I set the default channel with high priority as well on my API backend (nodeJS):

diff --git a/src/services/notifications/notifications.class.ts b/src/services/notifications/notifications.class.ts
index 69299c3..71c2e11 100644
--- a/src/services/notifications/notifications.class.ts
+++ b/src/services/notifications/notifications.class.ts
@@ -66,6 +66,8 @@ export class Notifications implements ServiceMethods<NotificationsData> {
       to: tokens.map((token: any) => token.token),
       title: data.title,
       body: data.body,
+      channelId: 'default',
+      priority: 'high',
     };
     try {
       const tickets = await expo.sendPushNotificationsAsync([message]);

I now have the notification pushed to the right channel, but this did not solve the initial issue: Notification are still not appearing when the app is closed on Android.

@charliecruzan are that the changes you was expected from me?

Those are the changes, so maybe there’s a OS-level setting you have set that is causing this (like battery optimization maybe?)

I already checked the notification settings and I didn’t see anything like that.

By the way, I have ton of other application sending background notification without any issue.

Si if it is the issue, I suppose the fix should be done on my app code/configuration, am I right?

Don’t you have any other suggestion to try?

I’m sorry I can’t give you more information right know, it’s pretty confusing to me too.

If you have time for that, I may share you the access to the codebase so you will have a complete view of what I done.

Thanks a lot for the assistance.

EDIT: I have the Asus ZenFone 101WD. It as an already provided battery saver system. Did you have similar experience feedback with this model?

@charliecruzan You intuition was the right one. Asus provides a built-in battery saver system with a whitelist of application that can start on boot:

And if I remove an application from the list, I am warn that notifications may not work:

And guess what? My application was not on the list.

So I am glad we identified the issue source, but this is still a problem has many of the users may have such a system.

I never touched this list as I reminder and some applications are already present on it.

Is there anyway with expo to check such information and ask the system to add my app to this kind of list?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.