Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to start activity through adb shell? [duplicate]

Tags:

android

People also ask

How do I launch an activity from adb?

You can use the start command from Activity Manager (am) a.k.a the adb shell am start -n command (via adb) specifying the app package name and the component name as defined in the manifest. You can add other parameters like ACTION (-a android. intent. action.

How do I run multiple adb shell commands?

But, in order to execute several commands in one line, you may use adb shell "cmd1;cmd2;cmd3" . The && command mentioned by @Rachit is not quite right, because in the case adb shell "netcfg && ps && getprop" , command ps will be executed only when netcfg is executed without error raised.

How do I launch an app from adb shell?

Show activity on this post. Then "chmod +x adb-run.sh" to make it executable. Note: This requires that you have Android Asset Packaging Tool ( aapt ) in your path. You can find it under the new build tools folder in the SDK.


Launch adb shell and enter the command as follows

am start -n yourpackagename/.activityname

eg:

MyPackageName is com.example.demo

MyActivityName is com.example.test.MainActivity

adb shell am start -n com.example.demo/com.example.test.MainActivity

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.


You can also find the name of the current on screen activity using

adb shell dumpsys window windows | grep 'mCurrentFocus'

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.)