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

Expo React Native安卓模拟器推送通知无法显示为横幅

Expo React Native安卓推送通知不显示横幅问题排查与解决

以下是针对你遇到的安卓模拟器推送通知仅在托盘显示、不弹出横幅问题的排查步骤和解决方案:

1. 验证通知通道的实际生效状态

Android 8.0+的通知行为完全由通知通道控制,代码中创建高重要性通道后,需确认模拟器中通道的实际配置:

  • 打开模拟器「设置」→「通知」→找到你的应用→进入「通知通道」→选择「default」通道
  • 确认通道的「重要性」为「高」,且**「横幅通知」选项已开启**

注意:通知通道一旦创建,后续代码修改无法更新已有通道,必须删除应用重装,或手动删除通道后重新创建。如果之前创建过低重要性通道,务必重装应用更新配置。

2. 优化后端推送Payload配置

在后端的推送消息中,补充Android通知的优先级和显示行为配置,确保触发横幅:

const notificationMessage = {
  to: expoPushToken,
  sound: "default",
  title: "New Connection Request",
  body: message,
  data: { message },
  android: {
    channelId: "default",
    icon: "ic_notification",
    color: "#000000",
    priority: "high",
    visibility: "public",
    // 新增以下配置,强制触发横幅
    notification: {
      priority: "high",
      importance: "high",
      defaultVisibility: "public",
      showWhen: true,
      enableVibration: true,
      enableLights: true
    }
  },
};

3. 确保通知通道在App启动时创建

将通道创建逻辑放在App启动的最早阶段(权限获取成功后),避免推送到达时通道尚未创建:

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

export default function App() {
  useEffect(() => {
    async function setupNotificationChannel() {
      const { status } = await Notifications.getPermissionsAsync();
      if (status === 'granted') {
        await Notifications.setNotificationChannelAsync("default", {
          name: "default",
          importance: Notifications.AndroidImportance.HIGH,
          vibrationPattern: [0, 250, 250, 250],
          lightColor: "#FF231F7C",
          showBadge: true,
          lockscreenVisibility: Notifications.AndroidNotificationVisibility.PUBLIC,
        });
      }
    }
    setupNotificationChannel();
  }, []);

  // 其他App逻辑...
}

4. 检查模拟器系统设置

  • 关闭「打扰模式」:下拉模拟器状态栏,确认静音/打扰模式未开启
  • 确认应用通知权限:进入「设置」→「应用」→你的应用→「通知」,确保「允许通知」开启,且「横幅通知」设置为「始终显示」

5. 尝试使用开发构建

Expo Go在处理通知通道时存在部分限制,建议创建开发构建替代Expo Go测试:

eas build --profile development --platform android

将构建后的APK安装到模拟器,再测试推送通知。

6. 真实设备验证

部分Android模拟器(如API 30版本)存在通知行为的兼容性bug,建议用真实安卓设备测试,确认是否为模拟器专属问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 04:58:12