Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I need to run my android app from a remote computer via SSH, but I'm not a command-line expert, so I would like to know: how to run a specific action of an app? (not just open it) Which implies: how to KNOW the exact sintax of possible actions of an app?

eg: I want to start a audio-recording app on my phone from my computer, AND start recording from remote. Is it possible?

Thanks, Andrea

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Use this:

am start -a android.intent.action.MAIN -n <package_name>/<full_class_name>

To control an app, you'll have to put correct values of <package_name> and <full_class_name> in the command. For example, you can use com.google.gmail/com.google.gmail.check_mail (Hypothetical names) as last part of command.

Obtaining package name of an app is easy, but obtaining class name of action isn't. There are two problems:

  1. Many app developers keep class info private.

  2. Not all developers do smart modular programming. Its good habit to divide an app in multiple classes which could be triggered by intents, but not all developers are smart.

Solution of 1st problem: Decompile the app using apktool and see all info. There are also other ways, but this one is always-working method (unless app is based on NDK instead of SDK).

Solution of 2nd problem: Nothing.

Don't worry, most of popular apps follow best programming practice and they provide Public API from which you can get class info.

share|improve this answer
    
Could you add some explanation on the parameters <package_name> and <full_class_name>, and how to obtain them? To me, at least the latter is not clear. –  Izzy Sep 29 '12 at 17:28
    
@Izzy Added the explanation... Review the answer, again. –  Sachin Shekhar Sep 29 '12 at 19:10
    
Thanks! +1 from me :D Compact and easy to understand. I will take the freedom to add some links, if you don't mind, for apktools (non-developers otherwise might think it's part of the SDK and get lost ;) –  Izzy Sep 29 '12 at 21:14
    
thank you! (Comments must be at least 15 characters in length.) –  Andrea Sep 30 '12 at 15:50

Like Sachin Shekhar said, you must use the following command :

am start -a android.intent.action.MAIN -n <package_name>/<full_class_name>

See a concrete example :

  • getting the apk file from your Android device or any Market places
  • running this command :

aapt dump xmltree com.android.settings*.apk AndroidManifest.xml

I would like to start "tethering" menu, so I search an activity in the output :

(...)
   E: activity (line=190)
    A: android:name(0x01010003)=".TetherSettings" (Raw: ".TetherSettings")
(...)

So the final command is :

am start -a android.intent.action.MAIN -n com.android.settings/.TetherSettings

The aapt command is part of the Android SDK

share|improve this answer
1  
:D Test it, it works as a charm. This is a real-life©®™ working example. –  sputnick Sep 29 '12 at 19:19
2  
Luck and computer science are quite opposite. It's a relative path. –  sputnick Sep 29 '12 at 19:34
2  
No, you can ommit the com.android.settings PATH, that's why I said it's relative. Test it on any app you'd like. –  sputnick Sep 29 '12 at 20:46
1  
I didn't say that it'll not work with other apps. The dot before class name does the magic. But, this shouldn't be encouraged. –  Sachin Shekhar Sep 30 '12 at 2:14
1  
You said that's luck, this is not. Do you have sources for your assertion ? Why this shouldn't be encouraged ? –  sputnick Sep 30 '12 at 2:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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