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

React Native Linking.getInitialURL()无法获取完整URL问题排查

解决React Native中Linking.getInitialURL()无法获取完整URL的问题

可能的原因及修复方案

1. ADB命令中的&符号被Shell解析为后台进程标记

你执行的ADB命令里,URL中的&会被系统Shell当作后台进程分隔符,导致&oobCode=23423432部分被截断,没有作为URL的一部分传递给App。

修复方法:

  • 用单引号包裹URL,避免Shell解析特殊字符:
    adb shell am start -W -a android.intent.action.VIEW -d 'https://curious-dev.web.app/verify/?mode=action&oobCode=23423432'
    
  • 或者转义&符号:
    adb shell am start -W -a android.intent.action.VIEW -d "https://curious-dev.web.app/verify/?mode=action\&oobCode=23423432"
    

2. AndroidManifest.xml的Intent Filter配置错误

如果ADB命令没问题,那大概率是App的Intent Filter没有正确匹配带查询参数的URL。

检查并修复配置:
确保AndroidManifest.xml中对应Activity的intent-filter配置正确,不需要在pathPrefix中包含查询参数(查询参数不属于路径部分):

<activity
  android:name=".MainActivity"
  android:launchMode="singleTask"> <!-- 注意launchMode设置,避免重复启动App -->
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data
      android:scheme="https"
      android:host="curious-dev.web.app"
      android:pathPrefix="/verify/" />
  </intent-filter>
</activity>
  • 不要使用android:path代替android:pathPrefix,android:path会严格匹配路径,不允许后续添加查询参数。
  • 确保launchMode设置为singleTask,这样App在后台时会被唤醒并接收完整的Intent数据。

3. 验证Intent数据是否完整

可以通过Android Logcat查看App接收到的Intent数据是否完整:

  1. 打开Logcat,过滤关键词Intent
  2. 重新执行ADB命令,查看输出的Intent的data字段,如果字段中已经缺失oobCode参数,说明问题出在ADB命令或系统传递环节;如果data字段完整,再排查React Native的Linking模块处理逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 20:40:25