How to get the main activity of the Android App for Appium

To automate the Android application, you need to specify the application package name and activity.

An Android application can have multiple activities. But we may not be able to launch all the activities. To find out the main activity, you can use below commands.

  1. adb shell pm list packages -f
  2. adb pull /system/app/Calculator/Calculator.apk
  3. aapt dump badging Calculator.apk

First command lists all the application paths and package names. Then second command copies the apk file from the emulator or device on the machine. Finally we have used aapt tool to find the main activity of the app. aapt tool is inside Android SDK directory\build-tools\23.0.2

Here are the screenshots of above commands.

list all packages from the android device

list all packages from the android device

Note that above command prints the package details for all apps in the device. You can use grep command to filter only specific apps as shown in below image.

Pulling the apk file of app from android device

Pulling the apk file of app from android device

As shown in above image, we have listed the package details for only calculator. Then we have pulled the apk file to system.

Finding the launchable activity in Android app

Finding the launchable activity in Android app

Once the apk file is available, you can get the launchable activity as shown in above image.

Here are some of the main activities of apps on Android Emulator.


Here are the main activities of some of the popular Android apps.

  2. com.viber.voip/.WelcomeActivity
  3. com.whatsapp/.Main

Note that if you try to launch the invalid activity, you will get the error saying Permission to start activity denied.

Android app can have multiple activities. To mark the specific activity as the starting activity, you have to add the intent-filter as shown in below example. Usually developers need to add below XML section app’s manifest file to make the specific activity as launchable.

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

You may also like...