0

so far I can get the available android devices and print them in the console in eclipse:

    String cmd = adbPath+" "+"devices";

    Process p;
    p=Runtime.getRuntime().exec(cmd);
    p.waitFor();

    String line;

    BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    while ((line = err.readLine()) != null){
        System.out.println(line);
    }
    err.close();

    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while((line=input.readLine())!=null){
        System.out.println(line);

        textArea.append("\n"+line);

    }
    input.close();

}

what I want is to display only the devices in jList or combobox ( if there is a better way please let me know) I created a JTextArea and using this line textArea.append("\n"+line); I can display

List of devices attached

0015c600 device

but I only need the device name ..

do you think that there is a way of taking only the device name and put it in a JList or combobox or any thing that will let the user to select the device?

Omarkk
  • 83
  • 1
  • 11
  • possible duplicate of [How to split a string in Java](http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – Alex P. Apr 21 '15 at 17:17
  • Hi Alex P, splitting may work when we deal with only one known device, but what if I get the following output: List of devices attached 0015c600 device 192.168.56.101:5555 device do we have another way of detecting only the devices? will split works on this ? – Omarkk Apr 21 '15 at 17:55
  • What exactly do you mean by the "name" - do you want "0015c600" and not "device" ? That's simple string splitting/parsing. Or do you want additional information that is not in the output of `adb devices` ? – Chris Stratton Apr 21 '15 at 18:32
  • Hi Chris, I only need to split the device name like this one "0015c600". I know how to display it in a jList for example. But, when I insert a new device, I need my code to split only the device/s name. so if I connect 4 devices for example, they will be splitter and only their name such as "0015c600" will be displayed only. thanks :) – Omarkk Apr 22 '15 at 08:08

0 Answers0