Push Notification

Android

Configuring Expo Push Notifications for Android

iOS
Android

Steps

Set up Firebase Cloud Messaging (FCM)

  • Follow the instruction described here to add Google Service Account

Make sure to add the role to your service account before uploading it to expo.dev credentials :

service-account

  • Make sure to use the same package name as your defined in your config.ts
appIdPrefix: "com.expostarter.app",

image

  • Download the google-services.json file into apps/myapp/ directory

Build with gitignored google-services.json file

The google-services.json file should not be committed to your repository, which is why it's listed in the .gitignore file.

However, this can cause local builds to fail. The best practice is to store this file in EAS secrets. You can do this using the following command:

eas secret:create --scope project --name GOOGLE_SERVICES_JSON \
  --type file --value ./google-services.json

Make sure in app.config.ts you have the following :

app.config.ts
{
  "expo": {
    "android": {
      "googleServicesFile": process.env.GOOGLE_SERVICES_JSON
    }
  }
}

Implement push notification handling

The project is pre-configured to present the user with a permission dialog when the user is first connected.

You can also trigger the permission dialog by calling setAppPreferences anywhere in your code :

home.tsx
export default function App() {
  const setAppPreferences = useSetAppPreferences();
 
  return(<Button onPress={() => {
      setAppPreferences({
        enableNotifications: true,
        hasPromptedForNotifications: true,
      });
    }}
  >
    <Text>
      Enable Notification
    </Text>
  </Button>)
}

Run your application on a device; simulators are not supported.

pnpm android -d

Test your setup

Token will be store and attached to the user in the backend

push token

Test your setup

android-notification

On this page

sidecard

No native development experience? No problem.

Use your existing web dev skills to get your app on the store!