I want to start activity through adb shell. So that I can launch a specific activity that is needed
-
charlesliublog.wordpress.com/2011/03/28/…– Vajk HermeczNov 14, 2012 at 14:24
6 Answers
Launch adb shell and enter the command as follows
am start -n yourpackagename/.activityname
-
28You can find out the activity names by running
aapt dump xmltree <APK> AndroidManifest.xml
and looking through the output. Jan 14, 2014 at 17:45 -
13You can find the apk on the phone with
adb shell pm list packages -f
and retrieve it withadb pull /path/to/file.apk C:\some\folder
to use with theaapt
command Chris commented. (aapt is in build-tools) May 29, 2014 at 23:12 -
26Also don't forget add
android:exported="true"
line for an activity in AndroidManifest.xml file.– mbelskyDec 1, 2015 at 6:56 -
1A simpler way to find the apk on the phone would be
adb shell pm path <package>
– DogeSep 28, 2016 at 20:51 -
4@ChristopherGalpin No need to pull the APKs,
adb shell dumpsys package
does the job.– m0skit0Jan 30, 2018 at 18:14
eg:
MyPackageName is com.example.demo
MyActivityName is com.example.test.MainActivity
adb shell am start -n com.example.demo/com.example.test.MainActivity
-
11^^^ This is correct explanation rather than " am start -n yourpackagename/.activityname " youre launch activity may be in different package, than in app pakagename Nov 21, 2016 at 8:51
-
It works for me only if I add quotes: adb shell am start -n "com.example.demo/com.example.test.MainActivity" Nov 19, 2021 at 11:52
-
You can also find the name of the current on screen activity using
adb shell dumpsys window windows | grep 'mCurrentFocus'
-
thanks a lot too, I had different build types, and strangely within the activity name, the suffix for the package isn't used :/ did learn something!– cV2Jun 1, 2017 at 12:40
-
Wow, really surprised. I can see every activity name of every app and every game even they have obfuscation! Oct 24, 2019 at 11:20
-
2The command doesn't seem to work anymore, at least on my emulator (grep returns nothing) :(– Rick77Mar 11, 2021 at 21:59
-
1
-
Maybe true before 2020, but now on june 2022 this does not show me anything on my Android TV Jun 11 at 20:17
I run it like AndroidStudio does:
am start -n "com.example.app.dev/com.example.app.phonebook.PhoneBookActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
If you have product flavour like dev
, it should occur only in application package name but shouldn't occur in activity package name.
For emulator, it works without android:exported="true"
flag on activity in AndroidManifest.xml
but I found it useful to add it for unrooted physical device to make it work.
adb shell am broadcast -a android.intent.action.xxx
Mention xxx as the action that you mentioned in the manifest file.
For example this will start XBMC:
adb shell am start -a android.intent.action.MAIN -n org.xbmc.xbmc/android.app.NativeActivity
(More general answers are already posted, but I missed a nice example here.)