Launch App via adb without knowing Activity name

AndroidAndroid IntentAdb

Android Problem Overview


From the post https://stackoverflow.com/questions/13380590/is-it-possible-to-start-activity-through-adb-shell, we can start an Android app via adb by

adb shell am start -n yourpackagename/.activityname

But is it possible to start an Android app via adb without knowing the Activity name? For example, by sending the android.intent.action.MAIN intent to a package? Maybe some command like this:

adb shell am start -a android.intent.action.MAIN -n packageName

Thanks!!

-Cosmo

Android Solutions


Solution 1 - Android

Yes, it is possible to launch an app via adb shell making use of the monkey tool.

Using the command from this answer:

adb shell monkey -p app.package.name -c android.intent.category.LAUNCHER 1

This command simulates the app icon click, so the intent implicit intent LAUNCHER is delivered to the specific receiver declared in app manifest (MAIN)

Solution 2 - Android

Using latest versions (at least API 25) you can start the default Activity, without knowing its name, and not using monkey:

PKG=com.android.calculator2
adb shell am start $PKG/$(adb shell cmd package resolve-activity -c android.intent.category.LAUNCHER $PKG | sed -n '/name=/s/^.*name=//p')

Solution 3 - Android

If you have the apk file, you can install and start the app using droidbot.

> droidbot -d emulator-5554 -a <xxx.apk> -install_app -policy none -count 0

DroidBot is based on adb, but it uses static analysis to extract the Activity name automatically.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhackjutsuView Question on Stackoverflow
Solution 1 - AndroidLeuOfIridiaView Answer on Stackoverflow
Solution 2 - AndroidDiego Torres MilanoView Answer on Stackoverflow
Solution 3 - AndroidYuanchun LiView Answer on Stackoverflow