Using the 'am'-Tool (Start Activities/Intens from a shell)

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Using the 'am'-Tool (Start Activities/Intens from a shell)

Postby rtreffer » Tue Dec 25, 2007 4:53 pm

Using the 'am'-Tool (Start Activities/Intens from a shell)


:?: Problems/Questions: Write them right below...

Description:
Android come with a "toolbox" shell and some tools to interact with the runtime/dalvikvm. One of these tools is "am", an Activity/Intent Manager/Messenger. am can be used to tryout intent from the command line, or to start activities (even with custom parameters).

The "full" documentation of am.
Code: Select all
./adb shell
# am
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>]
       am instrument [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>]
                [-w] <COMPONENT>

"start" will kick an intent. We just need to know what kind of intent we need.

Let's assume you have an activity "de.rtjava.andtest.myview.A1" and the package "de.rtjava.andtest" then you'll start the activity with

Code: Select all
adb shell
# am start -n de.rtjava.andtest/de.rtjava.andtest.myview.A1

or with
Code: Select all
adb shell am start -n de.rtjava.andtest/de.rtjava.andtest.myview.A1

This will start the requested activity. Ideal for ant or shell scripts (including .bat files)

So how about an location?
Code: Select all
adb shell am start 'geo:0,0?q=Munich,Germany'


Or the web?
Code: Select all
adb shell am start 'http://www.wikipedia.org'


Or edit your first contact?
Code: Select all
adb shell am start -a android.intent.action.EDIT -n 'com.google.android.contacts/com.google.android.contacts.EditContactActivity' -d 'content://contacts/people/1'


Don't forget to look at the LogCat to find out what intents are sent.

[EDIT]Reworked and added more samples[/EDIT]
root@localhost# : ( ) { : | : & } ; :
rtreffer
Junior Developer
Junior Developer
 
Posts: 15
Joined: Fri Nov 23, 2007 4:14 pm

Top

Postby derek_lan » Wed Dec 26, 2007 8:56 am

cool, this command should be run in Linux?
derek_lan
Freshman
Freshman
 
Posts: 8
Joined: Tue Dec 25, 2007 10:31 am

Postby rtreffer » Wed Dec 26, 2007 2:33 pm

derek_lan wrote:cool, this command should be run in Linux?

No. adb is available in your android sdk's tools directory. I've tested it under Linux, but it should work with Mac OS X and Windows.
Just open a command line window (Terminal in OS X, <windows key>+<r>, <c><m><d><return> under XP/Vista), navigate to the tools directory (cd <full path to android sdk>tools). Afterwards adb (or ./adb for Mac OS/Linux) will work :)
root@localhost# : ( ) { : | : & } ; :
rtreffer
Junior Developer
Junior Developer
 
Posts: 15
Joined: Fri Nov 23, 2007 4:14 pm

Postby plusminus » Thu Dec 27, 2007 12:01 am

Hello rtreffer,

Big thx for this Tutorial :)
Looking forward in seeing more :D

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Katharnavas » Thu Dec 27, 2007 6:17 am

Hi,
Its really a nice work.. Doing most of the activities thro command line..
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Postby rtreffer » Thu Dec 27, 2007 1:46 pm

plusminus wrote:Big thx for this Tutorial :)

Thanks for prettifying... It was quite low quality - just a 2 min. post of what I've discovered in >2h try and error ;)

We are currently try to start 5+ map apps at the same time, so eclipse/adt/launch isn't an option....
root@localhost# : ( ) { : | : & } ; :
rtreffer
Junior Developer
Junior Developer
 
Posts: 15
Joined: Fri Nov 23, 2007 4:14 pm

Top

Postby andtest » Mon May 04, 2009 9:12 pm

Thanks
andtest
Freshman
Freshman
 
Posts: 3
Joined: Fri Apr 17, 2009 1:33 am

Re: Using the 'am'-Tool (Start Activities/Intens from a shel

Postby adameve24 » Sat Dec 18, 2010 7:37 pm

can i use am tool to send email or record the call with a recorder in audio format ?
adameve24
Developer
Developer
 
Posts: 29
Joined: Wed Dec 15, 2010 12:32 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests