问题
I want to create a shortcut to start a particular AVD with specific parameters. If I create a batch file with start emulator.exe -avd myavd
the emulator.exe command window shows and remains after the device is started. Closing the emulator.exe window closes the device.
How can I start a device without seeing this window like the AVD Manager or Eclipse does?
回答1:
Create this java substituting the details for the avd you want:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class AVDs
{
public static void main(String[] args) throws IOException
{
List<String> avdCmd = new ArrayList<String>(args.length + 1);
avdCmd.add("C:\\Users\\Steve\\AppData\\Local\\Android\\sdk\\tools\\emulator.exe");
for (String cmdarg: args)
{
avdCmd.add(cmdarg);
}
ProcessBuilder launch = new ProcessBuilder();
launch.inheritIO().command(avdCmd).start();
}
}
Then use this as your shortcut:
"C:\Program Files\Java\jre1.8.0_40\bin\javaw.exe" -cp "S:\ADT workspace\AVDs\bin" AVDs -timezone Europe/London -avd Lollipop -scale 0.5
Substituting your classpath, or removing it if you don't need it. Make sure you use a path to javaw, don't just use java.
回答2:
As far as I know you can't. Even if you run emulator -avd Nexus_One from the Windows run dialog a command line like window opens. I can't see any options to hide this, like a silent mode either (running emulator -help shows available options). Eclipse has its own command line built in, so you don't see another window.
回答3:
I found an easy workaround, using SilentCMD
Create batch file, in my case my AVDs is called "PIXEL_MARSHMALLOW_6" so my batch is called emulator_marshmallow.cmd:
REM emulator_marshmallow.cmd
emulator @PIXEL_MARSHMALLOW_6
Run
c:\>SilentCMD emulator_marshmallow.cmd
This runs the emulator and the cmd.exe windows is hidden. BTW, I found many other utilities like SilentCMD here: https://www.raymond.cc/blog/hidden-start-runs-batch-files-silently-without-flickering-console/
来源:https://stackoverflow.com/questions/12313025/how-to-start-an-android-virtual-device-without-seeing-emulator-exe-window