How I can know the EMULATOR NAME in java code?

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

How I can know the EMULATOR NAME in java code?

Postby Fr4 » Sat Nov 21, 2009 1:27 am

this is my first post. I'm a new italian, newbie, android programmer.
I have a problem to test my application.
I would like to make a peer 2 peer application. This net is coordinated by a server to work as naming service.
This server have a ping service. Every client periodically open a socket to server to renew IP (that in real world can sometimes change).
With my emulator, all instances that run concurrently have

To contact the right peer, I must know the EMULATOR NAME, where previously I setted port forward by adb.

Somebody know how I can know the EMULATOR NAME of the running instance in java code???

Sorry for my strange request, and for my very bad english.

Thanks in advance,
Posts: 2
Joined: Sat Nov 21, 2009 12:54 am


Postby StaryLiu » Mon Dec 28, 2009 7:15 am

Hi :
Here is the code for how to get the emulator name from java code . I 've validated it .

as below code, you will get the a device name list .

public ArrayList<String> getDeviceList() {
ArrayList<String> deviceList = new ArrayList<String>();
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec("adb devices");
BufferedReader br = new BufferedReader(new InputStreamReader(p
String inline;
while ((inline = br.readLine()) != null) {
if (inline.startsWith("emulator")) {
StringTokenizer emulatorString = new StringTokenizer(inline);
} catch (IOException ex) {
return deviceList;
User avatar
Posts: 7
Joined: Mon Dec 28, 2009 6:54 am
Location: ShenZhen,China


Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests