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

如何通过adb shell使用Chrome打开本地文件?

解决adb shell调用Chrome打开本地文件的问题

问题出在文件路径权限与URI格式错误,以下是修正方案:

1. 将文件写入Chrome可访问的目录

Chrome默认无法访问shell私有目录的文件,需把测试文件放到外部存储的公共目录(比如/sdcard/Download),执行命令:

adb shell 'echo "This is a test input file" > /sdcard/Download/input.txt'

2. 用正确格式调用Chrome启动Intent

Android的am start命令需要指定完整的file协议URI,同时建议明确指定Chrome的包名,避免其他应用拦截Intent。执行命令:

adb shell am start -a android.intent.action.VIEW -d "file:///sdcard/Download/input.txt" -n com.android.chrome/com.google.android.apps.chrome.Main

关键原因说明

  • 原命令仅传input.txt,系统会把它当成网页域名而非本地文件路径,Chrome无法解析。
  • 外部存储公共目录(/sdcard/Download)是所有应用均可访问的路径,无需额外权限配置。
  • -n参数指定Chrome的启动组件,确保Intent被Chrome处理而非其他应用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 18:42:02