How to Run a Specific Android App Using Terminal

How to start an Android application from the command line?

adb shell
am start -n com.package.name/com.package.name.ActivityName

Or you can use this directly:

adb shell am start -n com.package.name/com.package.name.ActivityName

You can also specify actions to be filter by your intent-filters:

am start -a com.example.ACTION_NAME -n com.package.name/com.package.name.ActivityName

How to run terminal command in Android application?

You have to use reflection to call android.os.Exec.createSubprocess():

public String ls () {
Class<?> execClass = Class.forName("android.os.Exec");
Method createSubprocess = execClass.getMethod("createSubprocess", String.class, String.class, String.class, int[].class);
int[] pid = new int[1];
FileDescriptor fd = (FileDescriptor)createSubprocess.invoke(null, "/system/bin/ls", "/", null, pid);

BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fd)));
String output = "";
try {
String line;
while ((line = reader.readLine()) != null) {
output += line + "\n";
}
}
catch (IOException e) {}
return output;
}

How to start an application using Android ADB tools

adb shell
am start -n com.package.name/com.package.name.ActivityName

Or you can use this directly:

adb shell am start -n com.package.name/com.package.name.ActivityName

You can also specify actions to be filter by your intent-filters:

am start -a com.example.ACTION_NAME -n com.package.name/com.package.name.ActivityName 

How to execute android application in command line of Android Studio?

Update:
New location in Android Studio: View -> Tool Windows -> Terminal.

Also, the default keyboard shortcut is alt + F12.

Old:
Go to Tools -> Open Terminal. Works great.

open specific Activity from command line

So after hours of seeking the unknown i have found the solution.
In my app i m using some BuildVariants to differentiate working phases.

so instead of using the command

adb shell am start  -n com.my.app.activities/.ChatActivity

I should of used

adb shell am start -n com.my.app.MY_BUILD_VARIANT/com.my.app.activities.ChatActivity

thanks for the helpers

How do I launch the Android emulator from the command line?

I assume that you have built your project and just need to launch it, but you don't have any AVDs created and have to use command line for all the actions. You have to do the following.

  1. Create a new virtual device (AVD) for the platform you need. If you have to use command line for creating your AVD, you can call android create avd -n <name> -t <targetID> where targetID is the API level you need. If you can use GUI, just type in android avd and it will launch the manager, where you can do the same. You can read more about AVD management through GUI and through command line.
  2. Run the AVD either by using command emulator -avd <name> or through previously launched GUI. Wait until the emulator fully loads, it takes some time. You can read about additional options here.
  3. Now you have to install the application to your AVD. Usually during development you just use the same Ant script you used to build the project, just select install target. However, you can install the application manually using command adb install <path-to-your-APK>.
  4. Now switch to emulator and launch your application like on any normal device, through the launcher. Or, as an alternative, you can use the following command: adb shell am start -a android.intent.action.MAIN -n <package>/<activity class>. For example: adb shell am start -a android.intent.action.MAIN -n org.sample.helloworld/org.sample.helloworld.HelloWorld. As a commenter suggested, you can also replace org.sample.helloworld.HelloWorld in the line above with just .HelloWorld, and it will work too.


Related Topics



Leave a reply



Submit