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.
- 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 inandroid 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. - 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. - 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 commandadb install <path-to-your-APK>
. - 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 replaceorg.sample.helloworld.HelloWorld
in the line above with just.HelloWorld
, and it will work too.
Related Topics
How to Hide The Soft-Key Bar on Android Phone
Evenly Spaced Menu Items on Toolbar
How to Add Cardview in Layout Xml in Androidx
Ble Scan Is Not Working When Screen Is Off on Android 8.1.0
Way to Protect from Lucky Patcher/Play Licensing
How to Enable Cookies in Android Webview
Android - How to Get View from Context
Is There a Maximum Size to Android Internal Storage Allocated for an App
How To: Install Plugin in Android Studio
How to Programmatically Pair a Bluetooth Device on Android
What Would Happen If Android App Is Released with Debuggable On
Fragment in Viewpager Not Restored After Popbackstack
Android: How to Get a Modal Dialog or Similar Modal Behavior
Android: Wait on User Input from Dialog