0
点赞
收藏
分享

微信扫一扫

移动端测试获取主包名主类名Activity


移动端测试获取主包名主类名

我常用的一个方法

获取APP包名

1.先连接上手机,使用命令    adb shell am monitor

2.打开想要获取包名的APP

3.屏幕上就会出现你所打开的app包名信息

adb shell logcat | findstr  ActivityManager (真机运行应用,可以实时 查看当前正在运行的Activity)

adb shell “dumpsys window | grep mCurrentFocus”

说明:有引号是因为这个命令再Windows的cmd窗口运行,而windows(dos和nt)不支持grep命令,可以用findstr替换,在Mac及OS系统(基于unix)可以直接使用grep,这个需要注意一下就行。
在写代码的时候调用cmd命令这个也是要注意的。
所以,总结一下

adb shell dumpsys window | grep mCurrent (Mac)

adb shell dumpsys window | findstr mCurrentFocus(windows)

操作步骤也很简单,只需要打开你需要查找包名应用,然后再命令行窗口输入该命令回车即可查看。
mCurrentFocus和mCurrent区别也直接在示列中展示。

示列

现在我的Android设备打开了设置这个应用,电脑使用的是windows,两种方法都用一下。

C:\Users\Lvan8>adb devices
List of devices attached
HA17QKKD        device


C:\Users\Lvan8>adb shell dumpsys window | findstr mCurrentFocus
  mCurrentFocus=Window{1a44448 u0 com.android.settings/com.android.settings.Settings}

C:\Users\Lvan8>adb shell dumpsys window | findstr mCurrent
        mCurrentUserId=0
  mCurrentFocus=Window{1a44448 u0 com.android.settings/com.android.settings.Settings}
    mCurrent=[0,36][1200,1928]
    mCurrentAppOrientation=SCREEN_ORIENTATION_UNSPECIFIED
      mCurrentRotation=ROTATION_0

移动端测试获取主包名主类名Activity_android


这里可以明显的看到区别,不带Focus的显示的内容会相对来说多一点,可以根据自己的需求使用,再代码中写这个命令的时候记得管道符 | 需要转义。

dos命令
输入cls清屏

查看ativity

# Mac
adb shell dumpsys activity top | grep "ACTIVITY"

# Windows
adb shell dumpsys activity top | find "ACTIVITY"

C:\Users\Lvan8>adb shell dumpsys activity top | find "ACTIVITY"
  ACTIVITY com.google.android.youtube/com.google.android.apps.youtube.app.WatchWhileActivity b82123d pid=(not running)
  ACTIVITY com.tblenovo.launcher/com.android.searchlauncher.SearchLauncher 3236aef pid=2160
  ACTIVITY com.android.settings/.Settings af1c5f8 pid=31268

移动端测试获取主包名主类名Activity_包名_02


举报

相关推荐

0 条评论