npx skills add https://github.com/httprunner/skills --skill android-adb使用原始 adb 命令控制 Android 设备的参考。
adb -s <serial>。adb -s SERIAL shell wm size。# 启动 ADB 服务器
adb start-server
# 停止 ADB 服务器
adb kill-server
# 列出设备
adb devices -l
# 指定特定设备(当有多个设备在线时使用)
adb -s SERIAL <command>
# 启用 tcpip(需要先通过 USB 连接)
adb -s SERIAL tcpip 5555
# 获取设备 IP
adb -s SERIAL shell ip route | grep src
# 或
adb -s SERIAL shell ip addr show wlan0
# 通过网络连接
adb connect <ip>:5555
# 断开连接
adb disconnect <ip>:5555
# 屏幕尺寸
adb -s SERIAL shell wm size
# 当前前台应用(从 mCurrentFocus 获取包名/活动)
adb -s SERIAL shell dumpsys window | grep -E 'mCurrentFocus|mFocusedApp'
# 获取主屏幕启动器包名(用于返回主屏幕检测)
adb -s SERIAL shell cmd package resolve-activity --brief -c android.intent.category.HOME
# 原始 shell 命令
adb -s SERIAL shell <command>
Reference for controlling Android devices with raw adb commands.
adb -s <serial> whenever more than one device is connected.adb -s SERIAL shell wm size.# Start ADB server
adb start-server
# Stop ADB server
adb kill-server
# List devices
adb devices -l
# Target a specific device (use when multiple devices are online)
adb -s SERIAL <command>
# Enable tcpip (USB required first)
adb -s SERIAL tcpip 5555
# Get device IP
adb -s SERIAL shell ip route | grep src
# or
adb -s SERIAL shell ip addr show wlan0
# Connect over network
adb connect <ip>:5555
# Disconnect
adb disconnect <ip>:5555
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 验证包是否已安装
adb -s SERIAL shell pm list packages | grep <package>
# 通过包名启动(通过 monkey)
adb -s SERIAL shell monkey -p <package> -c android.intent.category.LAUNCHER 1
# 通过活动启动
adb -s SERIAL shell am start -W -n <package>/<activity>
# 通过 URI/协议启动
adb -s SERIAL shell am start -W -a android.intent.action.VIEW -d "<scheme://path>"
# 强制停止
adb -s SERIAL shell am force-stop <package>
# 点击
adb -s SERIAL shell input tap X Y
# 双击(两次点击,短暂延迟)
adb -s SERIAL shell input tap X Y && sleep 0.1 && adb -s SERIAL shell input tap X Y
# 长按(滑动到同一点并设置持续时间)
adb -s SERIAL shell input swipe X Y X Y 3000
# 滑动
adb -s SERIAL shell input swipe X1 Y1 X2 Y2 [duration_ms]
# 按键事件
adb -s SERIAL shell input keyevent KEYCODE_BACK
adb -s SERIAL shell input keyevent KEYCODE_HOME
adb -s SERIAL shell input keyevent KEYCODE_ENTER
# 返回主屏幕(重复按 BACK 键,检查前台是否为主屏幕启动器)
for i in $(seq 1 20); do
adb -s SERIAL shell input keyevent KEYCODE_BACK
sleep 0.5
# 通过比较当前焦点与主屏幕包名来检查是否已返回主屏幕
CURRENT=$(adb -s SERIAL shell dumpsys window | grep mCurrentFocus)
echo "Round $i: $CURRENT"
done
# 纯文本输入(仅限 ASCII,空格转义为 %s)
adb -s SERIAL shell input text "hello%sworld"
# 通过 ADB 键盘输入(支持 CJK 和特殊字符)
# 首先确保 ADB 键盘已激活:
adb -s SERIAL shell ime set com.android.adbkeyboard/.AdbIME
# 然后发送文本(base64 编码):
adb -s SERIAL shell am broadcast -a ADB_INPUT_B64 --es msg "$(echo -n 'your text' | base64)"
# 通过 ADB 键盘清除文本
adb -s SERIAL shell am broadcast -a ADB_CLEAR_TEXT
# 截图到本地文件
adb -s SERIAL exec-out screencap -p > screenshot.png
# 截图到设备然后拉取
adb -s SERIAL shell screencap -p /sdcard/screen.png
adb -s SERIAL pull /sdcard/screen.png ./screen.png
# 转储 UI 层级 XML
adb -s SERIAL shell uiautomator dump /sdcard/window_dump.xml
adb -s SERIAL pull /sdcard/window_dump.xml ./window_dump.xml
# 安装 APK(替换现有)
adb -s SERIAL install -r /path/to/app.apk
# 卸载
adb -s SERIAL uninstall <package>
| 键码 | 描述 |
|---|---|
KEYCODE_BACK | 返回键 |
KEYCODE_HOME | 主页键 |
KEYCODE_ENTER | 回车/确认键 |
KEYCODE_DEL | 删除/退格键 |
KEYCODE_VOLUME_UP | 音量加键 |
KEYCODE_VOLUME_DOWN | 音量减键 |
KEYCODE_POWER | 电源键 |
KEYCODE_TAB | Tab 键 |
KEYCODE_ESCAPE | Esc 键 |
每周安装量
171
仓库
首次出现
2026年1月21日
安全审计
安装于
codex160
gemini-cli159
opencode158
github-copilot155
cursor154
kimi-cli148
# Screen size
adb -s SERIAL shell wm size
# Current foreground app (package/activity from mCurrentFocus)
adb -s SERIAL shell dumpsys window | grep -E 'mCurrentFocus|mFocusedApp'
# Get home launcher package (for back-home detection)
adb -s SERIAL shell cmd package resolve-activity --brief -c android.intent.category.HOME
# Raw shell command
adb -s SERIAL shell <command>
# Verify package installed
adb -s SERIAL shell pm list packages | grep <package>
# Launch by package (via monkey)
adb -s SERIAL shell monkey -p <package> -c android.intent.category.LAUNCHER 1
# Launch by activity
adb -s SERIAL shell am start -W -n <package>/<activity>
# Launch by URI/scheme
adb -s SERIAL shell am start -W -a android.intent.action.VIEW -d "<scheme://path>"
# Force-stop
adb -s SERIAL shell am force-stop <package>
# Tap
adb -s SERIAL shell input tap X Y
# Double tap (two taps with short delay)
adb -s SERIAL shell input tap X Y && sleep 0.1 && adb -s SERIAL shell input tap X Y
# Long press (swipe to same point with duration)
adb -s SERIAL shell input swipe X Y X Y 3000
# Swipe
adb -s SERIAL shell input swipe X1 Y1 X2 Y2 [duration_ms]
# Key event
adb -s SERIAL shell input keyevent KEYCODE_BACK
adb -s SERIAL shell input keyevent KEYCODE_HOME
adb -s SERIAL shell input keyevent KEYCODE_ENTER
# Return to home (press BACK repeatedly, check foreground against home launcher)
for i in $(seq 1 20); do
adb -s SERIAL shell input keyevent KEYCODE_BACK
sleep 0.5
# Check if home reached by comparing current focus to home package
CURRENT=$(adb -s SERIAL shell dumpsys window | grep mCurrentFocus)
echo "Round $i: $CURRENT"
done
# Plain text input (ASCII only, spaces escaped as %s)
adb -s SERIAL shell input text "hello%sworld"
# Input via ADB Keyboard (supports CJK and special characters)
# First ensure ADB Keyboard is active:
adb -s SERIAL shell ime set com.android.adbkeyboard/.AdbIME
# Then send text (base64 encoded):
adb -s SERIAL shell am broadcast -a ADB_INPUT_B64 --es msg "$(echo -n 'your text' | base64)"
# Clear text via ADB Keyboard
adb -s SERIAL shell am broadcast -a ADB_CLEAR_TEXT
# Screenshot to local file
adb -s SERIAL exec-out screencap -p > screenshot.png
# Screenshot to device then pull
adb -s SERIAL shell screencap -p /sdcard/screen.png
adb -s SERIAL pull /sdcard/screen.png ./screen.png
# Dump UI hierarchy XML
adb -s SERIAL shell uiautomator dump /sdcard/window_dump.xml
adb -s SERIAL pull /sdcard/window_dump.xml ./window_dump.xml
# Install APK (replace existing)
adb -s SERIAL install -r /path/to/app.apk
# Uninstall
adb -s SERIAL uninstall <package>
| Keycode | Description |
|---|---|
KEYCODE_BACK | Back button |
KEYCODE_HOME | Home button |
KEYCODE_ENTER | Enter/confirm |
KEYCODE_DEL | Delete/backspace |
KEYCODE_VOLUME_UP | Volume up |
KEYCODE_VOLUME_DOWN | Volume down |
KEYCODE_POWER | Power button |
KEYCODE_TAB | Tab key |
KEYCODE_ESCAPE | Escape key |
Weekly Installs
171
Repository
First Seen
Jan 21, 2026
Security Audits
Installed on
codex160
gemini-cli159
opencode158
github-copilot155
cursor154
kimi-cli148
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
33,600 周安装