You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo推送通知在Android 11设备上无法显示的排查求助

Android 11设备(Nokia 7.2)上Expo推送通知无法显示的排查问题

前置条件

  • iOS端本地/推送通知均正常工作
  • Android端本地通知(前台/后台)正常工作
  • 使用eas独立开发构建的apk包
  • 设备中应用的所有通知权限已开启
  • ExpoToken配置正确,无报错
  • 推送凭证(Push ticket)和回执(receipt)发送无错误
  • FCM服务器密钥配置正确
  • 该设备上其他应用的推送通知可正常工作

没有其他Android设备可测试推送通知,请问能否在模拟器上测试?已尝试模拟器,但同样无法显示且无报错。

客户端代码

useEffect(() => {
      registerForPushNotificationsAsync().then((token) =>
        setExpoPushToken(token)
      );

    notificationListener.current =
      Notifications.addNotificationReceivedListener(setNotification(noti));

    responseListener.current =
      Notifications.addNotificationResponseReceivedListener((response) => {
        setNotification(response.notification);
      });

    return () => {
      notificationListener.current &&
        Notifications.removeNotificationSubscription(
          notificationListener.current
        );
      responseListener.current &&
        Notifications.removeNotificationSubscription(responseListener.current);
    };
  }, [user]);

  async function registerForPushNotificationsAsync() {
    let token;

    if (Platform.OS === "android") {
      await Notifications.setNotificationChannelAsync("default", {
        name: "default",
        importance: Notifications.AndroidImportance.MAX,
        vibrationPattern: [0, 250, 250, 250],
        lightColor: "#FF231F7C",
      });
    }

    if (Device.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;
      }
      token = (await Notifications.getExpoPushTokenAsync()).data;
      await user_ref(user.uid).update({
        ["push_token"]: token,
      });
      setToken(token);
    } else {
      alert("Must use physical device for Push Notifications");
    }

    return token;
  }

该代码与官方文档示例基本一致。

手动推送测试

发送通知的curl命令:

curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
  "to": "EXPOTOKEN",
  "title":"hello",
  "body": "world"
}'

响应结果:

{"data":{"status":"ok","id":"xxx-xxx-xxx-xxx-xxx"}}%  

查询推送回执的curl命令:

curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/getReceipts" -d '{
  "ids": [
    "xxx-xxx-xxx-xxx-xxx"
  ]
}'

响应结果:

{"data":{"xxx-xxx-xxx-xxx-xxx":{"status":"ok"}}}%

应用通知设置

应用通知设置截图

在无任何报错的情况下,我该从何处开始排查问题?


内容的提问来源于stack exchange,提问作者reactnative_newbie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 23:04:58