How to start an Android virtual device without see

2019-05-07 05:02发布

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?

3条回答
男人必须洒脱
2楼-- · 2019-05-07 05:07

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/

查看更多
爷的心禁止访问
3楼-- · 2019-05-07 05:10

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.

查看更多
对你真心纯属浪费
4楼-- · 2019-05-07 05:23

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.

查看更多
登录 后发表回答