Launch an app from Android shell terminal
If you want to launch an Android app from shell command line terminal there is a simply command allow to do that but you have to know some info about the app you want to execute. The command is named am and is basically a command line interface to the system ActivityManager.
The usage is the following:
usage: am [start|instrument] am start [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] [-c <CATEGORY> [-c <CATEGORY>] ...] [-e <EXTRA_KEY> <EXTRA_VALUE> [-e <EXTRA_KEY> <EXTRA_VALUE> ...] [-n <COMPONENT>] [-D] [<URI>]
The syntax is quite simple, just only:
am start -n [packageName]/[.activityName]
If you don't know these info the faster way for get the packageName and activityName data is to check the AndroidManifest.xml of the app you want to launch. Here a schematized structure with only the field we are interested in:
<manifest package="com.example.project" . . . > <application . . . > <activity android:name=".ExampleActivity" . . . > . . . </activity> . . . </application> </manifest>
Based to these info the example command line for launch this app will be:
am start -n com.example.project/.ExampleActivity
If you don't have the AndroidManifest.xml file the best way to get it would be to extract from the APK app you want to run. Indeed the APK format is a simple compressed file that you can open with each software able to manage it like 7z, WinRar, WinZip and so on. Once opened you'll find inside the xml file to get data from. As additional useful note if you want to terminate the running app the command is the following (always based to our app name example):
am kill com.example.project
This will close the app in the normal way. However if the app is locked in some way the command to force close in a "brute force" way is:
am force-stop com.example.project
Additional info about this command and all options available can be found here. Please note all the example commands showed here require you have already opened the android shell terminal. In case you want to run these command directly from adb tool you have to simply use this syntax:
adb shell am start -n [packageName]/[.activityName]
Using the red part you'll pass the command to adb for execution inside the connected target device.
Comments
Post a Comment