This document focuses on "getting the package name and Activity method", which is used to start the app when automating tests. The following methods are mainly derived from the contributions of the network and Community students, thank you!
1. Method One: PM The list package to view the pack name
adb shell pm list package -f
Will get the package name and path for all apk in the phone
adb shell pm list package -3 -f #获取第三方apk的包
2. Method Two: Dumpsys window (i most commonly used)
Open the apk you need to find and then start typing the above command
adb shell dumpsys window w | findstr \/ | findstr name=或adb shell dumpsys window |findstr mCurrent或adb shell "dumpsys window w|grep \/|grep name=|sed ‘s/mSurface=Surface(name=//g‘|sed ‘s/)//g‘|sed ‘s/ //g‘"
Note: Use sed here to replace part of the string with empty, in the format "sed ' s/to be substituted string/new string/g '"
3. Method Three: Logcat Log crawl Launcher
adb shell “ logcat | grep android.intent.category.LAUNCHER "或adb logcat ActivityManager:I *:s
4. Method Four: Dumpsys activity
Start the desired search apk, and then typing the above command
adb shell dumpsys activity | grep mFocusedActivity
5. Method Five: Logcat log catch start
C:\Users\Administrator>adb shell[email protected]_32_512:/ # logcat | grep START
Start the apk you need to find, then typing the above command to find the last Activitymanager
6. Method Six: AAPT tool (recommended)
Use the AAPT tool, suitable for the program to automatically get information about the APK, very practical,
AAPT is a tool that comes with the SDK, in the Sdk\builds-tools\ directory
1. For example, switch to the Aapt.exe directory in the command line to execute the Enter the following command
aapt dump badging D:\weixin658android1060.apk
2. The following two lines in the results of the run are the app package name and the portal activity name, and you can see the permissions, supported languages, and other information that the app uses.
7. Method Seven: Apktool anti-compilation app after viewing Androidmanifest.xml
1. Use Apktool to decompile the app
java -jar D:\Tools\apktool_2.2.3.jar d D:\Tools\weixin658android1060.apk
2. Open Androidmanifest.xml File
The Package property value for the manifest node is the app's bundle name:
Find the activity that corresponds to Android.intent.action.MAIN and Android.intent.category.LAUNCHER, the activity that corresponds to Android: The Name property is both the entry activity names, Android.intent.action.MAIN determines whether the application is displayed in the program list Activity,android.intent.category.launcher the application starts first
8. Method Eight: Use the monkey command to view activity
adb shell monkey -p com.tencent.mm -c android.intent.category.LAUNCHER -v -v 0|findstr Using
Note:
1. Findstr and grep Find string description
Findstr:windows platform Find string command, the general format is as follows:
adb shell xxx | findstr xxx
Grep:linux platform Find string command, usually first adb shell into the shell command line re-use, can also be used directly, the shell with grep after the command with double quotation marks:
adb shell "xxx | grep xxx"
Original address: https://testerhome.com/topics/9209 Thank the author hard summary
Appium Android Get package name and Activity in several ways (go)