文章目录
- I.指定设备
- II.启动、关闭APP
- 启动
- 通过action启动`-a`
- 通过包名类名启动`-n`
- 关闭
- III.截屏
- IV.录屏
- V.打印日志
- VI.系统相关
- A.查看进程
- B.内存占用
- C.CPU占用率
- D.清理APP缓存
- E.Android系统版本
- F.获取ROOT权限
- G.文件操作
- H.往/system目录下推送文件
- I.查看各分区大小
- J.发送广播
- VII.APK相关
- A.查询APP信息
- B.查看APK文件信息
- C.获取已安装的APK
- D.查看签名
I.指定设备
同时连接了多个机顶盒时,向指定机顶盒传递指令adb -s <IP>
例如:adb -s 192.168.0.100 shell am start -n a.b.c/a.b.c.activity
II.启动、关闭APP
启动
adb shell am start <-a>/<-n>
通过action启动-a
例:adb shell am start -a xxx.xxx.xxx
通过包名类名启动-n
包名:a.b.c
类名:a.b.c.MainActivity
例:adb shell am start a.b.c/.MainActivity
如果需要携带intent参数:adb shell am start -n a.b.c/.MainActivity --es <key1> <value1> --es <key2> <value2>
关闭
adb shell am force-stop <包名>
III.截屏
(建议使用采集卡,直接将画面输出到PC端方便截图等操作)
(测试时无效)adb shell screencap " -p | sed 's/\r$//'" > c:\Users\user\Desktop\screen.png
(测试时无效)adb shell screencap " -p | perl -pe 's/\x0D\x0A/\x0A/g' "> c:\Users\user\Desktop\screen.png
测试时有效:
1.先保存到机顶盒:adb shell screencap -p /sdcard/screen.png
2.再保存到PC端:adb pull /sdcard/screen.png c:\Users\user\Desktop\screen.png
IV.录屏
(建议使用采集卡,直接将画面输出到PC端方便截图等操作)
视频文件保存到机顶盒,步骤类似于III.截屏adb shell screenrecord /sdcard/demo.mp4
限制录制时间:adb shell screenrecord --time-limit 10 /sdcard/demo.mp4
(限制时间为10秒,不限制为180秒)
限制分辨率:adb shell screenrecord --size 1280x720 /sdcard/demo.mp4
(分辨率为1280x720,如果不指定默认使用手机的分辨率)
限制比特率:adb shell screenrecord --bit-rate 6000000 /sdcard/demo.mp4
(指定视频的比特率为6Mbps,如果不指定,默认为4Mbps)
V.打印日志
保存日志文件,文件保存到adb目录下,ctrl+c停止输出日志并保存文件adb shell logcat ->log.txt
如果需要使用过滤器:
1.先进入shell模式:adb shell
2.再使用logcat命令,并添加grep命令logcat | grep <过滤条件>
VI.系统相关
A.查看进程
adb shell ps
(可查看PID)
B.内存占用
adb shell dumpsys meminfo <pid>
C.CPU占用率
adb shell top
D.清理APP缓存
adb shell pm clear <包名>
E.Android系统版本
adb shell getprop
[ro.build.version.release] - 平台版本
[ro.build.version.sdk] - SDK版本
F.获取ROOT权限
adb root
adb remount
G.文件操作
adb push <文件路径> <推送目的路径>
推送文件adb pull
拉取文件
H.往/system目录下推送文件
在获取ROOT权限以后还需要设置system目录可读写adb shell
mount -o remount,rw /system
I.查看各分区大小
adb shell df
根据总空间和已用空间可快速定位挂载U盘的路径。
J.发送广播
adb shell am broadcast <-a> <-c> <-e>
-a --ACTION
-c --CATEGORY
-e --EXTRA_KEY
VII.APK相关
A.查询APP信息
adb shell dumpsys <包名>
B.查看APK文件信息
在SDK文件夹下的build-tools文件夹中找到aapt工具aapt dump badging <APK文件>
可以获得package:name和launchable-activity用于ADB启动APP
C.获取已安装的APK
如果不知道包名:adb shell pm list package
查看已安装APP的包名adb shell pm path <包名>
根据包名查询APK位置adb pull <地址>
获取APK
D.查看签名
解压缩APK文件,在META-INF文件夹下有个.RSA后缀的文件keytool -printcert -file <文件名>.RSA