Thursday, January 31, 2008

Run Android Application from Command Line

Sometime, we want to start the android application program from command line (Android Shell). Before, we usually clicking on the icon at application folder to run our program. So, there is an alternative way to run the program.

We use the Android Shell and issue am command to brought up the program. below is an example to do that.
1. Make sure that android emulator is running
2. Enter the shell with issuing command at command shell (prompt): adb shell
3. Issue am command. am command syntax is as follow :

am [start|instrument]
am start [-a <action>] [-d ] [-t <mime_type>]
[-c <category> [-c <category>] ...]
[-e <extra_key> <extra_value> [-e <extra_key> <extra_value> ...]
[-n <component>] [-D] [<uri>]
am instrument [-e <arg_name> <arg_value>] [-p <prof_file>]
[-w] <component>

for example we have android program with Manifest like below:

<manifest xmlns:android=""
  <application android:icon="@drawable/icon">
   <activity class=".Contact" android:label="@string/app_name">
    <action android:value="android.intent.action.MAIN" />
    <category android:value="android.intent.category.LAUNCHER" />

To run the code issue command like this (in one line):

am start -a android.intent.action.MAIN -n

ok, Have a nice try!

Do you want to learn more ?
Learning with sample code ?
Learning by Doing ?
Just Visit
and there is Android UI Design at there.


  1. You forgot the 'start' action:
    am start -a android.intent.action.MAIN ...

  2. Yes, thanks for the correction.
    And thanks for reading.

  3. You basically are using an Intent to start an Activity, but from the command line instead of from Java. Any idea how to pass arguments to the activity on the command line?

    This is the java equivalent code of what you did from the command line. The commented line is how you would pass an argument to the Intent, I would like to do the equivalent from the command line:
    Intent myIntent = new Intent();

  4. Would it be something like this?...

    am start -a android.intent.action.MAIN -n
    -e VALUE

  5. I have my Android phone connected to the adb shell and I want to be able to run a command that will allow me to open the Browser to browser wepages. I tried the settings and it worked but do not know how do this for the browser app. Here is what worked:

    am start -a android.intent.action.MAIN -n

  6. try this please
    "am start -a android.intent.action.MAIN -n"

  7. This comment has been removed by the author.

  8. hi how can I access Gmail app by this way?