ADB实用指令详解:管理文件、日志分析与设备操作,
adb文件管理指令
1.复制设备里的文件到电脑
adb pull [电脑上的目录]
电脑上的目录 参数可以省略,默认复制到当前目录
例:adb pull /data/tsplogtool /home/jxq/文档/场景魔方
2.复制电脑里的文件到设备
adb push
例:adb push 1.png /mnt/user/10/emulated/10/Movies
3.列出指定目录的内容
adb shell ls [options]
[options] 显示列表
- 无 列出目录下的所有文件和目录
- -a 列出目录下的所有文件(包括隐藏的)
- -i 列出目录下的所有文件和索引编号
- -s 列出目录下的所有文件和文件大小
- -n 列出目录下的所有文件及其 UID和 GID
- -R 列出目录下的所有子目录中的文件
- 切换到目标目录
adb shell cd
5.删除文件或目录
adb shell rm [options][options] 显示列表
- 无 删除文件
- -f 强制删除文件,系统不提示
- -r 强制删除指定目录中的所有文件和子目录
- -d 删除指定目录,即使它是一个非空目录
- -i 交互式删除,删除前提示
- 创建目录
adb shell mkdir [options]
- 无 创建指定目录
- -m 创建指定目录并赋予读写权限
- -p 创建指定目录及其父目录
7.输出当前目录路径
adb shell pwd8.复制文件和目录
adb shell cp [options]- source:源文件路径
- dest: 目标文件路径
9.移动或重命名文件
adb shell mv [options]- source:源文件路径
- dest: 目标文件路径
adb查看和查询xxx指令
1.查看日志
Android 的日志分为如下几个优先级(priority):按某级别过滤日志则会将该级别及以上的日志输出
V —— Verbose(最低,输出得最多)
D —— Debug I —— Info
W —— Warning
E —— Error
F—— Fatal
S —— Silent(最高,啥也不输出)
(1)打印日志
adb logcat | grep "Exception" --打印仅含"Exception"的日志
adb logcat *:W --打印严重级别W及以上的日志
adb logcat -c && adb logcat -s ActivityManager | grep "Displayed” --客户端程序启动时间获取
adb logcat -s "Tag" --输出指定Tag的日志信息(2)清空日志
adb logcat -c(3)将日志输出到文件
adb logcat > file-path2.查看四大组件
(1)查看top Activity
adb shell dumpsys activity top | grep ACTIVITY(2)查看前台 Activity命令
adb shell dumpsys activity activities | grep mResumedActivity(3)查看正在运行的 Services命令:
adb shell dumpsys activity services [](4)查看应用详细信息命令:
adb shell dumpsys package3.查看设备
(1)内存信息
adb shell cat /proc/meminfo(2)手机系统信息
adb shell "cat /system/build.prop | grep "product""(3)手机系统版本
adb shell getprop ro.build.version.release(4)手机系统api版本
adb shell getprop ro.build.version.sdk(5)手机设备型号
adb -d shell getprop ro.product.model(6)手机厂商名称
adb -d shell getprop ro.product.brand(7)手机存储信息
adb shell df获取手机内部存储信息:
魅族手机: adb shell df /mnt/shell/emulated
其他: adb shell df /data
获取sdcard存储信息:
adb shell df /storage/sdcard(8)手机分辨率
adb shell "dumpsys window | grep mUnrestrictedScreen"(9)手机物理密度
adb shell wm density(9)系统应用
adb shell pm list packages -s(9)系统第三方应用
adb shell pm list packages -3(10)包名包含某字符串的应用
使用 grep 过滤(windows 改用 findstr):
adb shell pm list packages | grep jingdong(11)应用安装路径
adb shell pm path4.查看文件
adb shell ls -l
对目录下包含的内容列举出来。
adb shell ls -a /sdcard/Download
显示sdcard路径下的所有文件(包括隐藏的)
5.查看当前界面信息
adb shell dumpsys window:
在dump出来的信息中,mCurrentFocus字段后面就是当前界面的一些信息,如Activity的名称等。
6.查看触摸信息
adb shell getevent:
其中的0035和0036分别对应触摸点的x和y坐标 。输出如下内容:
7.查看系统最近处理过的广播
adb shell dumpsys activity broadcasts
这段内容说明系统中最近一次处理的前台广播是“com.chinatsp.test3.TESTDEMO”,这是个有序广播,只有一个接收器在接受这个广播,该接收器位于进程com.chinatsp.test3中
8.列出当前所有activity信息
adb shell dumpsys activity activities
列出当前所有activity信息,其中可以看到堆栈信息,例如下面这段输出内容:
其中列出了其中一个堆栈(stack)中,当前一共有3个task,其中id为39的task中有两个Activity,其中最顶端的Activity是com.chinatsp.test3/.ShuxingActivity
9.查看当前wake_lock信
adb shell dumpsys power | grep -i wake
可以看出,当前是有进程“cn.kuwo.service.MainService”持有wake lock,并且wake lock的类型是PARTIAL_WAKE_LOCK。
10.列出所有service
adb shell dumpsys –l
11.列出当前stack列表信息
adb shell am stack list
adb启动和停止xxx指令
(1)启动应用/ 调起 Activity
adb shell am start [options]
[options] 参数可选:
- -a
action --指定 action,比如 android.intent.action.VIEW
- -c
category --指定 category,比如 android.intent.category.APP_CONTACTS
- -n
component 指定完整 component 名,用于明确指定启动哪个 Activity
[intent]能带数据
- --esn
extra-key null 值(只有 key 名)
- --ez
boolean值
- --ei
integer 值
- --el
long值
- --ef
float值
- --eu
URI值
- --ecn
component name
- --eia [,
- --ecn
- --eu
- --ef
- --el
- --ei
- --ez
- --esn
- -n
- -c
- -a
- 创建目录
- 切换到目标目录