How to Retrieve Android App Package Name and Activity for Automation Testing
This article explains several practical methods—including ADB commands, UIAutomatorViewer, source inspection, Appium, and AAPT—to obtain an Android application's package name and launch Activity, which are essential for configuring automation tools such as Appium.
Introduction
Anyone who has performed Android automation testing knows that the app's package name and main Activity are required, for example when configuring Appium's appPackage and appActivity capabilities.
This article introduces several ways to retrieve these values.
What are package name and Activity?
The package name uniquely identifies an Android app on the system; two apps may share a display name but cannot share the same package name. An Activity represents a single screen in the app, and the first screen launched is often called the launch Activity.
Methods
ADB
The simplest method is to run the following commands on a connected device:
adb shell
dumpsys activity | grep mFocusedActivity
UIAutomatorViewer
When only the package name is needed, launch uiautomatorviewer , open the target app, take a screenshot, and read the package name from the UI hierarchy.
Inspect source code
In Android Studio, open the Project Structure → Flavors panel and view the Application Id, which is the package name. If it is empty, open AndroidManifest.xml and read the package attribute. The launch Activity can be found by locating the android.intent.action.MAIN and android.intent.category.LAUNCHER intent filters and reading the android:name attribute.
Appium
After installing Appium, go to its settings page, select the APK file, and Appium will display the corresponding package name and Activity.
AAPT
Use the aapt command-line tool to dump the APK's manifest and extract the package and activity information.
These five approaches are quick and convenient; other techniques such as decompiling, logcat, Monkey scripts, etc., can also be used according to personal preference.
Qtest, the professional testing team under 360, provides testing technology platforms and daily updates on the latest testing techniques.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.