package com.doumee.keyCabinet.utils.i485; import android.content.Context; import android.hardware.usb.UsbConstants; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbInterface; import android.hardware.usb.UsbManager; import java.util.ArrayList; import java.util.List; public class SportUtils { public static List getSerialPortPaths(Context context) { UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); List devices = new ArrayList<>(usbManager.getDeviceList().values()); List serialPaths = new ArrayList<>(); for (UsbDevice device : devices) { for (int i = 0; i < device.getInterfaceCount(); i++) { UsbInterface intf = device.getInterface(i); if (intf.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) { serialPaths.add(device.getDeviceName()); break; } } } return serialPaths; } }