Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a specific Android app using Terminal? [duplicate]

I installed Eclipse and Android SDK already. Everything is running fine.

I want to install an .apk file so I follow the instruction already. But the problem is, when I start the emulator, it doesn't run my app automatically.

Is there a command in the terminal that allow me to run the specific app that I ask for it?

like image 361
Lam Tran Avatar asked Mar 31 '11 02:03

Lam Tran


People also ask

How do I run multiple instances of an app?

Open Two Instances Of An App Using 2Accounts On Android Enter 2Accounts, that lets you do the exact same thing as the Parallel Space app. Grab the app from the official Google Play Store and install it on your device. Open the app, choose the app you'd like to run multiple instances of, and tap on Enable at the bottom.

How do I launch an Android app from another app?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken button view to open YouTube application.


1 Answers

Use the cmd activity start-activity (or the alternative am start) command, which is a command-line interface to the ActivityManager. Use am to start activities as shown in this help:

$ 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>]        ... 

For example, to start the Contacts application, and supposing you know only the package name but not the Activity, you can use

$ pkg=com.google.android.contacts $ comp=$(adb shell cmd package resolve-activity --brief -c android.intent.category.LAUNCHER $pkg | tail -1) $ adb shell cmd activity start-activity $comp 

or the alternative

$ adb shell am start -n $comp 

See also http://www.kandroid.org/online-pdk/guide/instrumentation_testing.html (may be a copy of obsolete url : http://source.android.com/porting/instrumentation_testing.html ) for other details.

To terminate the application you can use

$ adb shell am kill com.google.android.contacts 

or the more drastic

$ adb shell am force-stop com.google.android.contacts 
like image 70
Diego Torres Milano Avatar answered Sep 21 '22 02:09

Diego Torres Milano