当前位置:首页>安卓APP>每天一个安卓测试开发小知识之常用的adb 命令

每天一个安卓测试开发小知识之常用的adb 命令

  • 2026-10-30 08:12:06
每天一个安卓测试开发小知识之常用的adb 命令
点击蓝字,立即关注

上期介绍了如何通过adb命令输入文字,本期介绍如何通过adb 点击坐标:

  • adb命令获取手机屏幕大小(分辨率);

  • adb命令点击坐标;

  • adb命令按下物理按键;

  • adb命令获取当前手机的旋转方向;

  • adb命令获取当前手机的折叠状态【针对折叠屏手机】。

01
获取手机屏幕大小(分辨率)
adb shell wm size

屏幕分辨率 横 1080 竖 2520

扩展

1. 查看 wm 命令帮助

adb shell wm help

2. 解锁屏幕【没有锁屏密码,屏幕已经点亮】

 adb shell wm dismiss-keyguard

3. 方向锁定

adb shell wm user-rotation lock

不锁定方向

adb shell wm user-rotation free

4.wm shell命令 4.1 获取帮助

adb  shell wm shell help

清除最近任务

adb shell wm shell recents clearAll

02
点击坐标
adb shell input tap 500 1000

查看input命令帮助

adb shell input help

input 命令可执行的指令包括:

  • tap <x> <y> (Default: touchscreen) 点击;

  • swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen) 滑动;

  • text <string> (Default: keyboard) 输入文字;

  • keyevent [--longpress|--duration <duration to hold key down in ms>] [--doubletap] [--async] [--delay <duration between keycodes in ms>] <key code number or name> ... (Default: keyboard) 模拟按下和释放物理按键 比如 home adb shell input keyevent 3。

# 数字键 0-9adb shell input keyevent 7    # 0adb shell input keyevent 8    # 1adb shell input keyevent 9    # 2adb shell input keyevent 10   # 3adb shell input keyevent 11   # 4adb shell input keyevent 12   # 5adb shell input keyevent 13   # 6adb shell input keyevent 14   # 7adb shell input keyevent 15   # 8adb shell input keyevent 16   # 9# 字母键 A-Zadb shell input keyevent 29   # Aadb shell input keyevent 30   # Badb shell input keyevent 31   # C# ... 以此类推
03
获取当前手机的旋转方向
adb shell settings get system user_rotation

命令settings表示直接操作手机设置,手机里很多设置项都可以使用 get 获取对应的值 put 设置对应的值

04
当前手机的折叠状态
 adb shell cmd device_state print-state

完全合上 3 完全打开 device_state 命令扩展

查看帮助

adb shell cmd device_state

比如获取当前手机支持的状态

adb shell cmd device_state print-states

adb shell cmd 

这个命令还有很多其他功能 我们后续继续分享 每天进步一点点!!!

END

链接:https://juejin.cn/post/7582787460418699306

本文为51Testing经授权转载,转载文章所包含的文字来源于作者。如因内容或版权等问题,请联系51Testing进行删除

点点赞
点分享
点在看

最新文章

随机文章