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

React Native Expo推送通知在Android设备无法显示问题求助

解决Expo Notifications Android推送无响应问题

基于你描述的情况(iOS正常、Android本地通知正常、已获取Token、权限排除),以下是针对性的排查和解决方向:

1. 补全Android通知渠道配置

Android 8.0(API 26)及以上版本要求必须创建通知渠道才能显示推送,本地定时通知可能默认使用了内置渠道,但远程推送需要显式指定已创建的渠道。

在你的通知初始化逻辑中添加渠道创建代码:

import * as Notifications from 'expo-notifications';
import { Platform } from 'react-native';

// 在App启动时调用此函数
async function initNotificationChannel() {
  if (Platform.OS === 'android') {
    const existingChannel = await Notifications.getNotificationChannelAsync('default');
    if (!existingChannel) {
      await Notifications.createNotificationChannelAsync('default', {
        name: '默认通知渠道',
        importance: Notifications.AndroidImportance.DEFAULT, // 控制通知优先级
        vibrationPattern: [0, 250, 250, 250],
        lightColor: '#FF0000',
      });
    }
  }
}

// 根组件中调用
useEffect(() => {
  initNotificationChannel();
  // 其他通知监听逻辑
}, []);

2. 校验远程推送Payload格式

Android推送要求必须指定channelId,且需与你创建的渠道ID一致。使用Expo Push API时,Payload需包含以下核心字段:

{
  "to": "你的Expo Token",
  "title": "通知标题",
  "body": "通知内容",
  "sound": "default",
  "channelId": "default" // 必须与创建的渠道ID匹配
}

3. 确认通知监听的注册时机

确保通知监听在App启动时立即注册,避免因组件挂载延迟导致推送事件丢失。示例代码:

useEffect(() => {
  // 监听通知到达
  const receiveSubscription = Notifications.addNotificationReceivedListener(notification => {
    console.log('收到通知:', notification);
  });

  // 监听通知点击
  const responseSubscription = Notifications.addNotificationResponseReceivedListener(response => {
    console.log('通知被点击:', response);
  });

  // 组件卸载时移除监听
  return () => {
    receiveSubscription.remove();
    responseSubscription.remove();
  };
}, []);

4. 检查App.json的Android配置补充

虽然你已排除权限问题,但可确认是否添加了Android 13+所需的通知权限(Expo SDK 48+会自动处理,手动添加可确保兼容性):
在android.permissions数组中添加:

"android.permission.POST_NOTIFICATIONS"

5. 验证EAS构建配置

如果使用EAS Build,确保expo-notifications已正确集成,无需额外插件配置,但需保证构建时使用的SDK版本与本地开发环境一致。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 12:41:33