Is it possible to start an actual Android application from the command line in Android? For example, say I'd simply like to start/bring to the front my calendar. Is there a way that I can do this like:

startapp com.google.calendar

Using adb, I believe it is possible:

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 as under:

<manifest xmlns:android="http://schemas.android.com/apk/res/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 com.app1.android.xtract/com.app1.android.xtract.Contact
  • Unfortunately, it doesn't work over SSH for me, but it does when running adb so I'll give you that :) – Naftuli Kay Jun 13 '11 at 17:49

All apps have different activities. There is an app that will help called QuickShortcutMaker that will assist you if you don't want to start decompiling apps to see their manifest files. Think you need to be root though to open apps via terminal.

# Examples

# From terminal emulator or adb as root open settings
am start com.android.settings/.Settings

# From ssh as root open settings
adb shell am start com.android.settings/.Settings

#Function to download a given url with chrome or stock browser
downloadurl(){ if [ $(pm list packages | grep -e 'com.android.chrome') ]; then am start -n com.android.chrome/com.google.android.apps.chrome.Main -d $1; sleep 10; input keyevent 4; return; fi; if [ $(pm list packages | grep -e 'com.android.browser') ]; then am start -a android.intent.action.VIEW -n com.android.browser/.BrowserActivity -d $1 && sleep 5; input keyevent 4; return; fi; am start -a android.intent.action.VIEW -d $1 && sleep 10; input keyevent 4; }
downloadurl "http://your.site.file.example.zip"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.