adb命令大全

416 阅读3分钟

这是我参与11月更文挑战的第2天,活动详情查看:2021最后一次更文挑战

查看设备app正在运行的activity

adb shell dumpsys activity activities
adb shell dumpsys activity | findstr "mFocusedActivity"  // 查看运行的app的activity
adb shell dumpsys activity | findstr "com.hx.herschel.wifitestdemo"

查看屏幕分辨率

adb shell wm size 

查看当前正在运行的进程列表

adb shell ps

可强行关闭进程

adb shell am force-stop 包名  
adb shell am force-stop  com.lejent.zuoyeshenqi.afanti

包名/启动类的名称

adb shell am start -n 
eg: adb shell am start -n com.xxx.xxx/com.xxx.xxx.SplashActivity 
adb shell am start com.huiyu.honeyrobot.car
adb shell am start com.huiyu.honeyrobot.car/.view.activity.OptionsWifiActivity
adb shell am start com.tencent.qqlivekid/.activity.WelcomeActivity

查看包名和activity

aapt dump badging apk路径

查看设备屏幕分辨率

adb shell wm size

查看手机装的所有app的包名:

adb shell pm list packages

查看系统应用的所有包名:

adb shell pm list packages -s

查看除了系统应用的第三方应用包名:

adb shell pm list packages -3 

查看包名和activity

aapt dump badging apk路径

查看设备设置

adb shell am start -n com.android.settings/com.android.settings.Settings
adb shell am start com.android.settings

D:\ 下载白名单

adb pull system/etc/lowmem_package_filter.xml

进入刷机模式

adb reboot loader

重新挂载 system 分区为可写

adb remount

传入和读取文件

adb push c:\hosts /etc/(把c盘根目录下的hosts文件传入手机etc目录下)
adb pull /etc/hosts c:\(把手机etc目录下的hosts文件传到c盘根目录下)

adb root
adb remount
adb pull /system/lib/hw/lights.rk312x.so d:\
adb push D:\lights.rk312x.so /system/lib/hw/

手机储存位置

/storage/sdcard0/Download

文件操作

adb shell /system/bin/screencap -p /sdcard/com.android.bluetooth

  • cd system/sd/data //进入系统内指定文件夹
  • ls //列表显示当前文件夹内容
  • rm -r xxx //删除名字为xxx的文件夹及其里面的所有文件
  • rm xxx //删除文件xxx
  • rm HY* //删除带有HY开头的文件
  • mkdir xxx // 创建xxx的文件夹
  • rmdir xxx //删除xxx的文件夹

打印日志

adb  logcat 
adb logcat >D:\log.txt  // 输出logo文件
C:\Windows\SysWOW64

更改亮度值(亮度值在0—255之间)

adb shell settings put system screen_brightness 150

获取超级权限

adb root

唤醒设备

adb shell
su
mount -o rw,remount /system
mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system
device.wake()

app安装

adb install 一共有lrtsdg六个选项
-l 锁定该应用程序
-r 替换已存在的应用程序,也就是说强制安装
-t 允许测试包
-s 把应用程序安装到sd卡上
-d 允许进行将见状,也就是安装的比手机上带的版本低
-g 为应用程序授予所有运行时的权限

获取MAC地址

adb shell  cat /sys/class/net/wlan0/address 

压力测试

随机触发一万条事件 adb shell monkey -p com.neoelite.ai 10000

查看内存

adb shell dumpsys meminfo com.handict.superapp_business_senior_next

杀死包名进程

adb shell am force-stop com.neoelite.ai

录制屏幕

录制屏幕以 mp4 格式保存到 /sdcard:
adb shell screenrecord /sdcard/filename.mp4
需要停止时按 Ctrl-C,默认录制时间和最长录制时间都是 180 秒。

如果需要导出到电脑:

adb pull /sdcard/filename.mp4
可以使用 adb shell screenrecord --help 查看 screenrecord 命令的帮助信息,下面是常见参数及含义:
参数含义
--size WIDTHxHEIGHT视频的尺寸,比如 1280x720,默认是屏幕分辨率。
--bit-rate RATE视频的比特率,默认是 4Mbps。
--time-limit TIME录制时长,单位秒。
--verbose输出更多信息。