adb基本使用

adb服务

  • adb start-server 开启服务
  • adb kill-server 停止服务

连接设备

  • adb connect 连接设备
  • adb disconnect 断开连接

查看设备

  • adb devices #查看设备信息
  • adb get-state #查看设备状态 device(正常连接),offline(连接异常),unknown(没有连接)
  • adb get-serialno #获取序列号
  • adb get-devpath #获取设备路径

多设备操作

adb -a 监听所有网络接口,而不仅仅是localhost
  -d 使用USB设备(如果多个设备连接错误)
  -e 使用TCP / IP设备(如果可用多个TCP / IP设备错误)
  -s 使用给定的序列号(覆盖ANDROID_SERIAL)
  -t 使用给定设备ID
  -h adb服务器主机名称(默认= localhost)
  -p adb服务器的端口(默认= 5037)
  -l 监听来自套接字的adb服务器(默认= tcp: localhost: 5037)

操作设备

  • adb shutdown 设备关机
  • adb reboot 设备重启
  • adb root 获取root权限
  • adb unroot 取消root权限

app 安装卸载

  • adb install E:/aa.apk 安装在电脑上的apk
  • adb install -r E:/aa.apk 覆盖安装 保留数据和缓存文件 -g 授予所有运行时权限
  • adb shell pm install /scard/picture 安装在手机上的apk
  • adb uninstall -k 包名
  • 在模拟器或者真机中需要使用 -s来指定

日志

  • adb logcat 查看日志
  • adb logcat -v time 打印详情日志,会记录当前的所有操作行为以及产生的结果,默认持续监听,按下Ctrl+c即可结束
  • adb logcat -v time >D:\log.txt 保存日志到电脑
  • adb logcat -f /sdcard/1.txt 保存日志到手机
  • adb logcat | findstr com.xx.xx 保存指定包名的日志
  • adb logcat -c 清除之前的日志输出

文件操作

把电脑上的文件传到手机储存卡中
adb push C:\Users\Administrator\Desktop\1.gif /sdcard/

把手机存储卡里的文件传到电脑
adb pull /sdcard/1.gif C:\Users\Administrator\Desktop\

截屏录屏

adb shell screencap /sdcard/1.png 当前窗口截屏保存到手机
adb exec-out screencap -p > 1.png 截图保存到电脑
adb shell screenrecord > 1.mp4 屏幕录像,Ctrl+c停止录制
注:模拟器和安卓4.4以下版本不支持录屏

查看app

  • adb shell pm list packages 所有应用
  • adb shell pm list packages -s #系统应用
  • adb shell pm list packages -3 #三方应用
  • adb shell pm list packages | findstr setting #过滤应用

查看activity

  • adb shell dumpsys package com.android.bluetooth 查看系统应用蓝牙的包名信息
  • adb shell dumpsys activity activities 查看所有的活动程序包名
  • adb shell dumpsys activity | findstr mFocusedActivity 查看当前启动的是哪个包
  • adb shell dumpsys window windows | findstr(grep) mFocusedApp
  • adb shell dumpsys window | findstr mCurrentFocus
posted @ 2022-05-18 23:59  小小滴人a  阅读(255)  评论(0编辑  收藏  举报