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

React Native Expo项目APK安装后无法唤起WhatsApp问题求助

React Native Expo 打包APK后WhatsApp无法识别的解决方案

核心问题原因

Expo Go调试环境已预配置常用APP的Scheme白名单,但自行打包的安卓APK受安卓11+包可见性限制,需手动声明允许访问的WhatsApp Scheme;同时网页版链接无法触发本地APP检测,必须使用原生Scheme。


解决步骤

1. 配置安卓Intent过滤白名单

在项目根目录的app.json中,为安卓添加intentFilters,声明允许启动WhatsApp的Scheme:

{
  "expo": {
    // 其他Expo配置
    "android": {
      "package": "com.your.app.package", // 替换为你的APP包名
      "intentFilters": [
        {
          "action": "VIEW",
          "data": [{"scheme": "whatsapp"}],
          "category": ["BROWSABLE", "DEFAULT"]
        }
      ]
    }
  }
}

2. 修改代码使用原生Scheme并编码消息

放弃网页版https://api.whatsapp.com链接,改用WhatsApp原生whatsapp://Scheme,同时对消息文本做URL编码避免参数失效:

import { Linking, Alert, Platform } from 'react-native';

const whatsApp = async () => {
  const phoneNumber = Platform.OS === 'ios' ? '601234567891' : '+601234567891';
  const rawMessage = `My Message.`;
  const encodedMessage = encodeURIComponent(rawMessage);
  
  // 区分平台使用对应链接:iOS兼容网页版,安卓必须用原生Scheme
  const url = Platform.OS === 'ios' 
    ? `https://api.whatsapp.com/send?phone=${phoneNumber}&text=${encodedMessage}`
    : `whatsapp://send?phone=${phoneNumber}&text=${encodedMessage}`;

  try {
    const supported = await Linking.canOpenURL(url);
    if (!supported) {
      Alert.alert('错误', '设备未安装WhatsApp,请安装后重试。');
      return;
    }
    await Linking.openURL(url);
  } catch (err) {
    Alert.alert('错误', '打开WhatsApp时出错,请稍后重试。');
  }
};

3. 确保打包配置生效

  • 若使用EAS Build,确认eas.json中的安卓配置未覆盖app.json的intentFilters;
  • 若使用旧版expo build:android,重新打包前清理缓存(expo r -c)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 20:45:39