以下命令部分是需要有root权限的
1. 获取手机中执行Monkey的进程号 :
adb shell pgrep commands.monkey
2. 查看前台显示的Activity:
adb shell dumpsys window | grep mCurrentFocus
3. 获取手机的分辨率:
adb shell wm size
4.飞行模式开:
adb shell settings put global airplane_mode_on 1
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true
5. 飞行模式关:
adb shell settings put global airplane_mode_on 0
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false
6. 设置灭屏时间(单位毫秒):
adb shell settings put system screen_off_timeout 30000
7. 自动亮度关:
adb shell settings put system screen_brightness_mode 0
8. 方向锁定开:
adb shell settings put system accelerometer_rotation 0
9. 方向锁定关:
adb shell settings put system accelerometer_rotation 1
10. WIFI开:
adb shell svc wifi enable
11. WIFI关
adb shell svc wifi disable
12. NFC开
adb shell svc nfc enable
13. NFC关
adb shell svc nfc disable
14. BT开
adb shell service call bluetooth_manager 6
15. BT关
adb shell service call bluetooth_manager 8 i32 1
16. 关闭GPS(回到低耗电量):
adb shell "settings put secure location_providers_allowed -gps"
17. 开启GPS(回到高精确度):
adb shell "settings put secure location_providers_allowed +gps"
18. 拨打电话
adb shell am start -a android.intent.action.CALL -d tel:10086
19. 清除batterystatus:
adb shell dumpsys batterystats --reset
20. 获取机器开机时长
adb shell cat /proc/uptime
21. 获取当前手机的电量百分比:
adb shell cat /sys/class/power_supply/battery/capacity
22. 获取当前手机的电池容量大小:
adb shell cat /sys/class/power_supply/bms/charge_full_design
23. 获取实时电池端输出的电流:
adb shell cat /sys/class/power_supply/battery/current_now
24. 获取实时电池端的输出电压:
adb shell cat /sys/class/power_supply/battery/voltage_now
25. 获取当前wake_lock:
adb shell cat /sys/power/wake_lock
26. 设置自定义的wake_lock(设置完之后手机不能深睡):
adb shell "echo test > /sys/power/wake_lock"
27. 获取当前屏幕是否点亮:
adb shell dumpsys power | grep Display
28. 强制退出某个应用:
adb shell am force-stop com.android.settings
29. 清除某个应用的所有数据:
adb shell pm clear com.android.settings
30. 打开某个应用:
adb shell am start com.android.settings/.MainSettings
31. 清除logcat信息:
adb logcat -c
32. 查看logcat 并过滤关键字:
adb logcat | grep LAUNCHER
33. 获取当前手机的配置信息:
adb shell getprop
34. 获取当前手机的亮度(不同手机节点可能不一样):
adb shell cat /sys/class/backlight/panel0-backlight/brightness
或 adb shell cat /sys/class/leds/lcd-backlight/brightness
或 adb shell cat /sys/class/backlight/lcd-backlight/brightness
35. 获取当前CPU频率:
比如8核手机0-3是小核,4-7是大核
查看小核实时频率 adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
查看大核实时频率 adb shell cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq
36. 获取CPU可用频率的档位:
查看小核实时频率 adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
查看大核实时频率 adb shell cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_available_frequencies
37. 模拟点击:
adb shell input tap 100 200
38 . 输入框输入文本:
adb shell input text abcdefg
39. 模拟滑动
adb shell swipe 100 100 500 500
40. 下发keyevent事件
adb shell input keyevent 3
常用的事件:
KEYCODE_HOME=3;
KEYCODE_BACK=4;
KEYCODE_CALL=5;
KEYCODE_ENDCALL=6;
KEYCODE_0=7;
KEYCODE_1=8;
KEYCODE_2=9;
KEYCODE_3=10;
KEYCODE_4=11;
KEYCODE_5=12;
KEYCODE_6=13;
KEYCODE_7=14;
KEYCODE_8=15;
KEYCODE_9=16;
KEYCODE_VOLUME_UP=24;
KEYCODE_VOLUME_DOWN=25;
KEYCODE_POWER=26;
KEYCODE_CAMERA=27;
41. 打开手机中的视频音频文件
adb shell am start -a android.intent.action.VIEW -t audio/* -d file:///sdcard/Alarms/XXXX.mp3
adb shell am start -a com.miui.videoplayer.LOCAL_VIDEO_PLAY -d file:///sdcard/Alarms/XXXXX.mp4(小米手机自带播放器)
42. 浏览器打开指定网页
adb shell am start -a android.intent.action.VIEW -d www.baidu.com -n com.android.browser/.BrowserActivity(手机自带浏览器)
43. dump当前页面的xml信息
adb shell uiautomator dump --compressed (--compressed当前窗口的UI布局简化信息)
44. 查看芯片平台:
adb shell getprop ro.soc.model
45. 发送短信
adb shell am start -a android.intent.action.SENDTO -d sms:12345678901 --es sms_body testMessage
adb shell input keyevent 22 //向右转移焦点到 发送按钮上
adb shell input keyevent 66 //回车键,发送消息
46. 获取logcat中打印的关键信息,不阻塞,在一些自动化中可能会用得到
adb logcat -d | grep XXX
47…… 待发现好玩的命令 更新
更多可参考:https://github.com/mzlogin/awesome-adbGitHub - mzlogin/awesome-adb: ADB Usage Complete / ADB 用法大全