public static Set < String > findAllDevices ( AndroidDebugBridge adb , Integer minApiLevel ) { Set < String > devices = new LinkedHashSet <> ( ) ; for ( IDevice realDevice : adb . getDevices ( ) ) { if ( minApiLevel == null ) { devices . add ( realDevice . getSerialNumber ( ) ) ; } else { DeviceDetails deviceDetails = DeviceDetails . createForDevice ( realDevice ) ; int apiLevel = deviceDetails . getApiLevel ( ) ; if ( apiLevel == DeviceDetails . UNKNOWN_API_LEVEL || apiLevel >= minApiLevel ) { devices . add ( realDevice . getSerialNumber ( ) ) ; } } } return devices ; }
Find all device serials that are plugged in through ADB .