Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get emulator given name of device, or vice versa [duplicate]

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.

like image 866
Kvass Avatar asked Jul 08 '13 15:07

Kvass


People also ask

How do I find my android device name?

Open the Settings app to check your device information: Tap About phone. Take note of your device name.

How do I change my device name on emulator?

In android go to Settings > Applications > Development and tap on Device Hostname. You can then change the name and it should show up when attached to adb.


1 Answers

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:

  1. Find emulator's port number (5554):

    $ adb devices
    List of devices attached
    emulator-5554   device
    
  2. 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

like image 100
alex.dorokhov Avatar answered Sep 30 '22 14:09

alex.dorokhov