Road to capture all connected devices using java code at run time

In this post you will learn how to capture connected devices udid at run time using java code.

public static List<String> getAttachedDevicesList(){
 
  List<String> devicesID = new ArrayList<String>();
  try {
         Process process = Runtime.getRuntime().exec("adb devices");       
         BufferedReader reader=new BufferedReader( new InputStreamReader(process.getInputStream()));
         String s;                
         while ((s = reader.readLine()) != null){         
          if(s.contains("device") && ! s.contains("attached")){
           String[] device = s.split("\t");
           devicesID.add(device[0]);
          }
         }  
        
     } catch (IOException e) {
         e.printStackTrace();
     }
     return devicesID;
 }


public static void main(String[] str) {
  List<String> devicesID = getAttachedDevicesList();
  for (String dvc : devicesID) {
   System.out.println(dvc);
  }
 }

When you run this you will get  all connected devices  udid.

No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution