Android notifications are not working with expo 39 - (expo managed) when app is killed from background

Please provide the following:

  1. SDK Version: 39.0.0
  2. Platforms(Android): Android

@ charliecruzan Need help on this.
We have setup expo managed app but its notifications are not working when the app is idle or killed from the background, the notifications are coming if the app screen is opened and active, if I keep the phone idle then it’s not working after few minutes(5 or 10 minutes).

We are using:
“expo-notifications”: “~0.7.2”
“expo”: “^39.0.0”,

Tried with below settings in app.json


"android": {
      "useNextNotificationsApi": false,
      "googleServicesFile": "./google-services.json",
      "permissions": []
    }
OR
"android": {
      "useNextNotificationsApi": true,
      "permissions": []
    }

Called below function in componentDidmount

Any idea why it’s not working do i need FCM setup for expo managed app? I have tested it with both with FCM or without FCM both not seems to working for me

registerForPushNotificationsAsync = async () => {
  if (Constants.isDevice) {
    const { status: existingStatus } = await Notifications.getPermissionsAsync();
    let finalStatus = existingStatus;
    if (existingStatus !== 'granted') {
      const { status } = await Notifications.requestPermissionsAsync();
      finalStatus = status;
    }
    if (finalStatus !== 'granted') {
      alert('Failed to get push token for push notification!');
      return;
    }
    const token = (await Notifications.getExpoPushTokenAsync()).data;
    console.log(token);
    this.setState({ expoPushToken: token });
  } else {
    alert('Must use physical device for Push Notifications');
  }
  if (Platform.OS === 'android') {
    await Notifications.setNotificationChannelAsync('default', {
      name: 'default',
      importance: Notifications.AndroidImportance.HIGH,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: '#902929'
    });
  }
};

@ charliecruzan expo 39 sdk managed expo notification not working after some time, but when i just open the app its start working how to sole this? please help.

we are calling this api using php cron:

$message_body = [
		"to" => <push token>
		"title" => "title",
		"body" => 'text test',
		"priority" => "high",
		"ttl " => "2419200 ",
		"data" => array("date" => 'date', "region" =>'india'),
	];
	"https://exp.host/--/api/v2/push/send", [
			'method' => 'POST',
			'timeout' => 15,
			'httpversion' => '2.0',
			'headers' => [ "content-type" => "application/json" ],
			'body' => json_encode( $message_body ),
		]

charliecruzan
I have also tried it first without priority and ttl and also by adding its value both not seems to working and we are using expo cli 4.4.3 versions

Yes, you need to setup FCM: Using FCM for Push Notifications - Expo Documentation

But if it’s working while the app is opened then that’s probably not the option. What do you mean by “it’s not working”? Notifications are not coming through at all when the app is backgrounded (no UI is shown and they aren’t in the system tray?)

Sounds like this is the same as [expo-notifications] Notifications stop being received after around 5 minutes of device inactivity · Issue #10456 · expo/expo · GitHub, so you should read there for context and the solution

@charliecruzan - Thanks for your reply,and thanks for confirming we need FCM keys configured in expo to make it working for the managed workflow.

The notifications are not shown if the app is not opened or aren’t the system try. and thanks for the ticket sharing BUT I already checked it and the priority level set to “high” is the only solution I found. What according to you the issue? and i have also test it with postman some by passing data with token manually to this end point https://exp.host/--/api/v2/push/send and the same thing happens after few time not getting any notification. Thanks again for your reply.

@charliecruzan - Not sure what was wrong, Today again try to upload FCM server key using expo push command, previously was uploading it manually now its working fine.

1 Like

@bpathania add the following to useEffect in your App.js
Notifications.setNotificationHandler({ handleNotification: async () => ({ shouldShowAlert: true, shouldPlaySound: true, shouldSetBadge: true, }), });