Skip to content

ADB

官方说明文

应用信息

  • 查看当前显示Activity栈:adb shell dumpsys activity activities
  • 查看应用详情:adb shell dumpsys package <packageName>
  • 打开设置界面:adb shell am start com.android.settings
  • 回到桌面: adb shell input keyevent KEYCODE_HOME

实时资源占用情况(性能监控)

sh
adb shell top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ]
    -m num  最多显示多少个进程
    -n num  刷新多少次后退出
    -d num  刷新时间间隔(单位秒,默认值 5)
    -s col  按某列排序(可用 col 值:cpu, vss, rss, thr)
    -t      显示线程信息
    -h      显示帮助文档
sh
adb shell dumpsys meminfo com.example.app  # 应用内存详情
adb shell dumpsys gfxinfo com.example.app  # 渲染性能(帧率)

设备硬件与系统信息

sh
adb shell wm size #屏幕分辨率
adb shell wm density #屏幕密度
adb shell getprop ro.product.model #查看型号
adb shell cat /proc/cpuinfo #cpu信息
adb shell cat /proc/meminfo #内存信息
adb shell ps #进程 或者adb shell ps | grep <packageId>
adb shell "kill -9 4417"  #  4417代表进程名
adb shell ifconfig wlan0 #查看设备ip
adb shell pm list packages -3 #第三方包ID,非系统应用

# getconf
adb shell getconf PAGE_SIZE #获取内存PAGE_SIZE大小

# dumpsys 
adb shell dumpsys window displays #所有显示屏信息
adb shell dumpsys battery #查看电池

# getprop 获取设备信息
adb shell getprop ro.build.version.release    # Android 版本
adb shell getprop ro.product.model            # 手机型号
adb shell getprop ro.product.model #型号
adb shell getprop ro.product.brand #品牌
adb shell getprop ro.product.name #设备名
adb shell getprop ro.product.manufacturer #制造商
adb shell getprop ro.product.device #硬件平台

设备网络信息

sh
adb shell ip addr show wlan0

启动与关闭

强制停止:adb shell am force-stop <packagename> 打开APP或Activity

sh
adb shell am start -n <package_name>/<activity_name>
adb shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n <package_name>/<activity_name>

# 打开浏览器
adb shell am start -a android.intent.action.VIEW -d https:#baidu.com

adb shell am start -a "xx.intent.action.MAIN" [应用包名]方式需要配置AndroidManifest.xml文件:

xml
<intent-filter>
  <action android:name="xx.intent.action.MAIN"/>
  <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

截屏与录屏

sh
adb exec-out screencap -p > screen.png    # 截图
adb shell screenrecord /sdcard/demo.mp4   # 开始录屏(Ctrl+C 停止)
adb pull /sdcard/demo.mp4 .               # 拉取视频

模拟输入

sh
adb shell input tap 500 1000        # 点击 (x, y)
adb shell input swipe 100 100 500 500  # 滑动

adb shell input text "6901285993015" && adb shell input keyevent 66

这里是模拟一个输入字符串6901285993015,并回车(回车键对应键码 66,在 Android 系统中定义为 KEYCODE_ENTER)。

Logcat

清空:adb logcat -c