android代码使⽤adb,使⽤adb命令操控Android⼿机(⽰例代
码)
1) ⼿机连接电脑之前
⾸先,查看安卓⼿机是否已经连接上电脑
adb devices
让adb⼀直查安卓设备,到后才停⽌
adb wait-for-device
2) ⼿机连接电脑后的操作
2.0) 基本命令
连接多个安卓设备时,在adb命令后紧跟着使⽤ -s加序列号 来指定要操作的设备
建议每次只连接⼀个安卓设备进⾏操作
建议每次只连接⼀个安卓设备进⾏操作
建议每次只连接⼀个安卓设备进⾏操作
$ adb devices
List of devices attached
FA6AX0301341 device
ce0217122b56b02604 device
$ adb -s FA6AX0301341 shell
sailfish:/ $
2.1) 锁定/解锁/重启/关机
锁定/解锁⼿机
adb shell input keyevent 26 //锁定⼿机
adb shell input keyevent 82 //解锁⼿机(如果设置了密码,会提⽰输⼊密码)
输⼊密码,并回车
adb shell input text 123456 && adb shell input keyevent 66
重启/关机
adb reboot //重启
adb shell reboot //重启
adb shell reboot -p //关机
2.2) 系统设置
打开关闭蓝⽛
adb shell service call bluetooth_manager 6 //打开蓝⽛
adb shell service call bluetooth_manager 9 //关闭蓝⽛
adb shell svc wifi enable //打开wifi
adb shell svc wifi disable //关闭wifi
打开wifi设置界⾯
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings 连接时保持亮屏 设置
svc power stayon [true|false|usb|ac|wireless]
参数解释:
true: 任何情况下均保持亮屏
false:任何情况下均不保持亮屏(经过设定的时间后⾃动⿊屏)
usb, ac, wireless:设置其中之⼀时,仅在这⼀种情况下才保持亮屏。
2.3) 模拟本机操作
模拟按键操作
adb shell input keyevent 111 //关闭软键盘(其实是按下ESC,111=KEYCODE_ESCAPE)
模拟滑动触屏操作
adb shell input touchscreen swipe 930 880 930 380 //向上滑
adb shell input touchscreen swipe 930 880 330 880 //向左滑
adb shell input touchscreen swipe 330 880 930 880 //向右滑
adb shell input touchscreen swipe 930 380 930 880 //向下滑
模拟⿏标操作
adb shell input mouse tap 100 500
100是x,500是y。
原点在屏幕左上⾓。
2.4) 运⾏程序
adb shell am start -a android.intent.action.CALL -d tel:10010
打开⽹站
启动APP
adb shell am start -n com.package.name/com.package.name.MainActivity
adb shell am start -n com.package.name/.MainActivity
$ adb shell monkey -p acts -c android.intent.category.LAUNCHER 1 Events injected: 1
## Network stats: elapsed time=16ms (0ms mobile, 0ms wifi, 16ms not connected)
3) 硬件⾼级调节
查看设备序列号
adb get-serialno
3.1) CPU相关
查看CPU温度
先查看有哪些温度区域thermal zone
$ adb shell ls sys/class/thermal/
cooling_device0
cooling_device1
cooling_device2
cooling_device3
cooling_device4
cooling_device5
thermal_zone0
thermal_zone1
thermal_zone2
thermal_zone3
thermal_zone4
thermal_zone5
thermal_zone6
thermal_zone7
查看某个CPU温度
$ cat /sys/class/thermal/thermal_zone0/temp
25800
温度是milliCelsius,所以这⾥是25.8度C。
CPU设置
查看当前⼿机可⽤的governor
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors userspace interactive performance
锁定CPU为最⼤频率
设置CPU governor为performance。
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 4) 刷机
重启⼿机,进⼊recovery或bootloader模式
adb reboot recovery //恢复模式
adb reboot bootloader //刷机模式。不同⼿机,命令不同,要试⼀下。
adb reboot-bootloader
adb reboot boot loader
进⼊ fastboot 模式。
adb reboot fastboot
安卓intent用法
关机,然后同时按住 增加⾳量 和 电源 键开机
5) 调试
抓取开机⽇志
adb wait-for-device && adb shell logcat -v threadtime | tee mybootup.log
查看⽇志
adb logcat
关闭/重启adb服务进程
adb kill-server
adb start-server
从本地复制⽂件到设备,或者反之
adb push test.zip /sdcard/ //从本地复制⽂件到设备
adb pull /sdcard/abc.zip ~/ //从设备复制⽂件到本地
显⽰已经安装的APP的包名
adb shell pm list packages
安装、删除APP
adb install abc.apk //第⼀次安装。如果⼿机上已经有此app,则会报错。
adb install -r abc.apk //如果已经安装过,保留原app的数据
adb -s 11223344 install abc.apk //当多个安卓连接到电脑时,安装到指定⼀台安卓上adb ample.appname
查看apk的版本(⽆需解压)
aapt dump badging abcd.apk |grep version
捕获键盘操作
adb shell getevent -ltr
查看屏幕分辨率 dpi
wm density
wm size
设置:
wm density 240⽴刻⽣效。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。