通过ADB命令查看当前Android运行程序的页面信息

1、前言

  通常在接手别人的App项目的时候,遇到的一个最令人头疼的问题就是当前手机上看到的这个页面对应哪个 Activity 或者 Fragment,这种时候,我们就可以通过ADB命令打印当前页面

2、adb 安装

  由于我安装了Android 的开发环境,所以直接切换到Android SDK的路径下运行 adb 命令即可

(TIPS:如何切换到 SDK/platform-tools 目录下输入adb 还是提示 “不是内部或外部命令,也不是可运行的程序批处理文件。”,可以执行 adb start-server 试试,如果还是不行,那就自己再找办法吧)

3、常用 adb shell 命令

1、查看已连接的设备
  adb devices 

2、获取app包名和启动名:
  ①  mac/linux:     adb shell dumpsys window windows | grep mFocusedApp

  ②  win:            adb shell dumpsys window windows | findstr mFocusedApp
3、查看当前栈顶的Activity的Fragment :
  adb shell dumpsys activity your.package.name
4、指定某台设备:
  adb -s 设备号
  (tips:当有多台设备连接了adb 的时候,执行 adb shell 命令,adb 需要指定设备号,例: adb -s 64d62615 shell dumpsys window windows | findstr mFocusedApp)
5、卸载APP:
  adb uninstall xxxx(包名)

原文地址:https://www.cnblogs.com/lkc9/p/11238451.html