Android 小票打印USB
第一步USB通信: Usb设备有两种,Host与Accessory 简单来说是主模式与从模式,主模式则android设备给外设供电,反之,外设给android设备充电,对于小票打印,使用的是Host模式 用到以下几个类: 1.UsbManager: 这个类用来获取USB设备-UsbDevice UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); // 获取设备 HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); UsbInterface & UsbEndpoint : 代表UsbDevice有哪些功能 UsbInterface intf = device.getInterface(0 ); // 官方文档上边是这样写的,直接获取第一个,但往往不一定只连接一个设备,就要求我们找到自己想要的那个,一般的做法是 int count = device.getInterfaceCount(); for ( int i = 0;i < count; i++ ) { UsbInterface intf = device.getInterface(i); // 之后我们会根据 intf的 getInterfaceClass