Android get emulator given name of device, or vice versa

adb, android-emulator

Solution

It's possible with telnet to emulator. It's not a single command unfortunately, but in general it's possible to automate it with shell. Here is the basic idea:

Find emulator's port number (5554):

$ adb devices
List of devices attached
emulator-5554   device

Telnet to emulator:

$ telnet localhost 5554
Trying 127.0.0.1...
Connected to localhost.
...
OK
avd name
Nexus7

Nexus7 is the avd name.

See also this answer to find how to make telnetting in one line: https://stackoverflow.com/a/5608081

Problem

Currently when I run `adb devices` it gives me a list of devices that looks something like: ``` emulator-5554 device emulator-5556 device ``` My goal is to find a command that I can run in the shell that takes a device name as a parameter, e.g. `Nexus7` and returns the corresponding device serial, e.g. `emulator-5554`. If that isn't possible, I want to be able to have a function that takes `emulator-5554` as the parameter and returns `Nexus7` (the opposite direction of the former function) which I will then loop over all the devices in `adb devices` and figure out which one matches `Nexus7`. UPDATE I found a workaround solution which was to specify the port number when I launch the avd and then I know which emulator maps to which avd name, but ideally I would still like to know the answer here.

Original source

Related problems