android的usb连接外设返回connection为null的问题

ydww 发布于 2013/04/23 19:45
阅读 434
收藏 0

@lucasli 你好,想跟你请教个问题:最近也在做usb连接外设,代码如下

manager = (UsbManager) getSystemService(Context.USB_SERVICE);
		HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
		System.out.println("deviceList.size------" + deviceList.size());
		Toast.makeText(getApplicationContext(),
				"deviceList.size------" + deviceList.size(), 1).show();
		// UsbDevice device = deviceList.get("deviceName");
		for (UsbDevice device : manager.getDeviceList().values()) {
			System.out.println("检测到设备------" + device);
			if (device.getVendorId() == 6790 && device.getProductId() == 29987) {// 对应的设备
				System.out.println("device------" + device);
				UsbInterface intf = device.getInterface(0);
				System.out.println("intf------" + intf);
				UsbEndpoint endpoint = intf.getEndpoint(0);
				System.out.println("endpoint------" + endpoint);
				connection = manager.openDevice(device);
				System.out.println("connection-------" + connection);
				// connection.claimInterface(intf, false);
			}
		}

前面都运行正常,但在最后一行输出connection=null,请问这是怎么回事呢?有空时劳烦帮看一下,谢谢了!

加载中
返回顶部
顶部