Expo push notification is not working after building the android apk

In my app i used expo push notification it works fine in development in both the device ios and android but after making build apk it works only on ios. I don’t know why its is not working on android.

Here is my notification code

import React, { ReactNode, useEffect, useRef, useState } from "react";

import * as Notifications from "expo-notifications";

import * as Permissions from "expo-permissions";

import Constants from "expo-constants";

import { Platform, View } from "react-native";

import restServices from "../services/restServices";



interface NotificationProps {}

Notifications.setNotificationHandler({

  handleNotification: async () => ({

    shouldShowAlert: true,

    shouldPlaySound: false,

    shouldSetBadge: false,

  }),

});

async function registerForPushNotificationsAsync() {

  let token;

  if (Constants.isDevice) {

    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") {

      alert("Failed to get push token for push notification!");

      return;

    }

    token = (await Notifications.getExpoPushTokenAsync()).data;

   

  } else {

    alert("Must use physical device for Push Notifications");

  }

  if (Platform.OS === "android") {

    Notifications.setNotificationChannelAsync("default", {

      name: "default",

      importance: Notifications.AndroidImportance.MAX,

      vibrationPattern: [0, 250, 250, 250],

      lightColor: "#FF231F7C",

    });

  }

  return token;

}

const Notification = () => {

  const [expoPushToken, setExpoPushToken] = useState("");

  const [notification, setNotification] = useState<boolean | any>(false);

  const notificationListener: any = useRef<any>();

  const responseListener: any = useRef<any>();

  useEffect(() => {

    registerForPushNotificationsAsync().then((token: any) =>

      setExpoPushToken(token)

    );

    notificationListener.current = Notifications.addNotificationReceivedListener(

      (notification) => {

        setNotification(notification);

      }

    );

    responseListener.current = Notifications.addNotificationResponseReceivedListener(

      (response) => {

        console.log("######res", response);

      }

    );

    return () => {

      Notifications.removeNotificationSubscription(notificationListener);

      Notifications.removeNotificationSubscription(responseListener);

    };

  }, []);

  console.log("notification", notification);

  useEffect(() => {

    if (expoPushToken !== "") {

      const _rest = new restServices();

      _rest

        .post(`/notification/token?token=${expoPushToken}`, {})

        .then((res) => {

          console.log("tokenR", res);

        })

        .catch((err) => {

          console.log("tokenRError", err);

        });

    }

  }, [expoPushToken]);


  return null;

 

};

export default Notification;

Has anyone been able to fix this? I have the same problem

not yet

you need to make sure you follow instructions for how to configure this on android :slight_smile: we can do it automatically for you on ios, but google requires you to do some manual work on android.

see Using FCM for Push Notifications - Expo Documentation

1 Like

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