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

  1. is it possible to install apk file using am without adb if yes how?

    ReplyDelete
  2. You need adb only for remotely connect to your device from PC. Other way would be to use some terminal app in your local device and launch the command. Remember you need the root level and usually standard app have system level only that the android into device have to be rooted.

    ReplyDelete
  3. Can I launch APK without using command line in terminal shell ? Is it possible to launch app ?

    ReplyDelete
  4. Sorry, don't understand very well the question. You mean launch an app from code?

    ReplyDelete
  5. can i install a apk file through command line with out using ADB.

    ReplyDelete
    Replies
    1. No from what I know since adb is the command line utility for "communicate" with android device. Basically the communication is based to some protocol that, in this case, is managed by adb. I guess the only way is to develop a "custom" adb executable who will execute only the single apk lauch command you need...

      Delete
    2. thank you for this good content, is it possible to execute it via Metasploit meterpreter? in a case like gaining the shell via meterpreter and execute the am command to run an installed app

      Delete
  6. can i run system apps of android

    ReplyDelete

Post a Comment

Popular posts from this blog

Access GPIO from Linux user space

Android: adb push and read-only file system error

Tree in SQL database: The Nested Set Model