adb 常用命令

前言

adb,全称是 Android Debug Bridge,广泛用于 Android 开发者的调试中。

# 查看设备链接
adb devices			//列出设备,返回设备号和设备状态
# 安装和卸载
adb install xxx.apk  	//安装程序
adb install -r xxx.apk  	//覆盖安装
adb -s abcdefg install xxx.apk	//安装程序到设备号为adbcdefg的设备上
adb uninstall com.test.app 	//使用包名卸载程序
# 文件操作
adb pull /storage/emulated/0/xxx.apk	//复制sd卡下文件到当前目录
adb push xxx.apk /storage/emulated/0/	//复制当前目录文件到存储卡目录
# 进入终端
adb shell	//进入终端后,以下操作即可省略 'adb shell'
# 数据处理(pm)
adb shell pm clear com.test.app   //清空程序数据
adb shell pm list packages		//查看app名称
# 事件输入(input)
adb shell input text "insert%syour%stext%shere"  //输入文字
adb shell input tap 500 1450	//模拟点击坐标(500, 1450)
adb shell input swipe 100 500 100 1450 100  //模拟滑动,从(100, 500)至(100, 1450),持续100ms
adb shell input swipe 100 500 100 500 500    //模拟长按坐标(100, 500),持续500ms
adb shell input keyevent 25  //调低音量,根据AOSP中KeyEvent类中事件常量定义
# 活动管理(am),部分命令需root后操作
adb shell am start com.test.app/com.test.app.MainActivity  //启动软件com.test.app中的活动 MainActivity
adb shell am start -a "android.intent.action.VIEW" -d "https://www.google.com"  //使用隐式intent启动浏览器打开网页,需root
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED  //发出启动完成的广播,Android11不允许
adb shell am startservice com.test.app/com.test.app.MyService  //启动软件com.test.app中的服务MyService
# 事件输出
adb logcat  //显示设备当前日志
# 系统信息(dumpsys)
adb shell dumpsys	//查询所有系统信息,包括活动、管理器、界面管理器、输入、电源、进程、电池、闹钟、内存等信息
adb shell dumpsys activity // 查询AMS(ActivityManagerService)信息
adb shell dumpsys package // 查询PMS(PackageManagerService)信息
adb shell dumpsys window // 查询WMS(WindowManagerService)信息
adb shell dumpsys input // 查询IMS(InputManagerService)信息
adb shell dumpsys power // 查询PMS(PowerManagerService)信息
adb shell dumpsys procstats // 进程统计(ProcessStatsService)
adb shell dumpsys battery // 电量信息(BatteryService)
adb shell dumpsys alarm // 闹钟信息(AlarmManagerService)
adb shell dumpsys meminfo //内存信息
# 屏幕截图及录制
adb shell screencap /sdcard/screen.png 
adb shell screenrecord /sdcard/screen.mp4
# 查看进程及cpu使用
adb shell ps
adb shell top
posted @ 2022-03-05 20:45  wx2020  阅读(112)  评论(0编辑  收藏  举报