Android USB Create Connection 完整过程
来源:互联网 发布:女生都穿安全裤 知乎 编辑:程序博客网 时间:2024/06/03 17:28
private void connect2Usb() { Logger.t(TAG).d("connect2Usb : connect"); // 1 获取Usbmanager mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE); // 2 获取UsbDevice HashMap<String, UsbDevice> usbDevices = mUsbManager.getDeviceList(); // 3 遍历UsbDevices, 查找USB Device Set<Map.Entry<String, UsbDevice>> entrySet = usbDevices.entrySet(); UsbDevice usbDevice= null; for (Map.Entry<String, UsbDevice> entry : entrySet) { Logger.t(TAG).d("connect2Usb : " + entry.getKey() + "," + entry.getValue()); //find your usb device if (entry.getValue().getVendorId() == USB_VENDORID) { usbDevice= entry.getValue(); break; } } if (usbDevice== null) { Logger.t(TAG).e("no usb devices"); return; } if (usbDevice.getInterfaceCount() <= 0) { Logger.t(TAG).e("no usb devices interface "); return; } //[4] 查找Usb Interface mUsbInterface = usbDevice.getInterface(0); Logger.t(TAG).d("usb interface : " + mUsbInterface); //[5] 查找 Endpoints for (int i = 0; i < mUsbInterface.getEndpointCount(); i++) { UsbEndpoint endpoint = mUsbInterface.getEndpoint(i); if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) { mUsbEndpointIn = endpoint; if (mUsbEndpointIn.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { Logger.t(TAG).d("usb bulk transfer"); } } if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) { mUsbEndpointOut = endpoint; } //for test int direction = endpoint.getDirection(); Logger.d("direction " + direction); } // [5] 检查usb权限 boolean hasPermission = mUsbManager.hasPermission(usbDevice); if (!hasPermission) { Logger.t(TAG).e("no usb permission"); //[7] 申请usb权限 PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 9898, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_ONE_SHOT); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); registerReceiver(mUsbReceiver, filter); mUsbManager.requestPermission(usbDevice, mPermissionIntent); return; } //[8] Open usb Device, create connection if (mUsbDeviceConnection == null) { mUsbDeviceConnection = mUsbManager.openDevice(usbDevice); } //[9] claim UsbInterface if (mUsbDeviceConnection != null) { boolean claimUsb = mUsbDeviceConnection.claimInterface(mUsbInterface, true); if (claimUsb) { Logger.t(TAG).d("claimed usbinterface"); } } //开始USB Communication。 //... }
阅读全文
0 0
- Android USB Create Connection 完整过程
- android create project 过程初探
- Android系统升级的完整过程
- Create boot usb
- Android服务查询完整过程源码分析
- Android服务注册完整过程源码分析
- Android Binder- 一次完整的通信过程
- Ubuntu QT for Android完整搭建过程
- Ubuntu QT for Android完整搭建过程
- Android服务注册完整过程源码分析
- Android服务查询完整过程源码分析
- Create a connection-oriented socket
- Android studio 启动时出现Android studio was unable to create a local connection in order
- USB 过程
- USB 过程
- Linux USB subsystem --- USB create HCD
- Linux USB subsystem --- USB create HCD
- Linux USB subsystem --- USB create HCD
- HttpClient连接池的连接保持、超时和失效机制
- H264码流结构分析
- CSS预处理器——Sass、LESS和Stylus实践【未删减版】著作权归作者所有。 商业转载请联系作者获得授权,非商业转载请注明出处。 原文: http://www.w3cplus.com/css/
- MVC、MVP、MVVM三种模式的比较
- 2017暑假实习
- Android USB Create Connection 完整过程
- QQ第三方登陆回调处理
- nodejs Assignment to constant variable
- 字符串-leetcode 72 Edit Distance
- Jfinal调用存储过程方法
- android TextView实现跑马灯效果
- fig14-09
- 高清时代4K H.265/HEVC来临---OTT/IPTV直播系统大发展
- 域名劫持原理及实现