android获取USB设备的名称
1.注释内 。是三星设备可能不支持,需要更换的代码。
2.mUsbManager。是getSystemService(Context.USB_SERVICE)获的。
3. 从stackoverflow摘过来的。源地址找不到咧。
protected static final int STD_USB_REQUEST_GET_DESCRIPTOR = 0x06;
// http://libusb.sourceforge.net/api-1.0/group__desc.html
protected static final int LIBUSB_DT_STRING = 0x03;
public String getUSBName() {
String strusbName = null;
HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
if (deviceList.size() == 0) {
return strusbName;
}
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
if (deviceIterator.hasNext()) {
UsbDevice device = (UsbDevice) deviceIterator.next();
strusbName = device.getDeviceName();
Log.d("", "Name: " + device.getDeviceName()+"\n"
+ "VID: " + device.getVendorId()
+ " PID: " + device.getProductId());
UsbInterface intf = device.getInterface(0);
int epc = 0;
epc = intf.getEndpointCount();
Log.d("","Endpoints:" + epc + "\n");
Log.d("","Permission:" + Boolean.toString(mUsbManager.hasPermission(device)) + "\n");
UsbDeviceConnection connection = mUsbManager.openDevice(device);
if(null==connection){
Log.d("","(unable to establish connection)\n");
} else {
// Claims exclusive access to a UsbInterface.
// This must be done before sending or receiving data on
// any UsbEndpoints belonging to the interface.
connection.claimInterface(intf, true);
// getRawDescriptors can be used to access descriptors
// not supported directly via the higher level APIs,
// like getting the manufacturer and product names.
// because it returns bytes, you can get a variety of
// different data types.
byte[] rawDescs = connection.getRawDescriptors();
String manufacturer = "", product = "";
try
{
byte[] buffer = new byte[255];
int idxMan = rawDescs[14];
int idxPrd = rawDescs[15];
int rdo = connection.controlTransfer(UsbConstants.USB_DIR_IN
| UsbConstants.USB_TYPE_STANDARD, STD_USB_REQUEST_GET_DESCRIPTOR,
(LIBUSB_DT_STRING << 8) | idxMan, 0, buffer, 0xFF, 0);
manufacturer = new String(buffer, 2, rdo - 2, "UTF-16LE");
rdo = connection.controlTransfer(UsbConstants.USB_DIR_IN
| UsbConstants.USB_TYPE_STANDARD, STD_USB_REQUEST_GET_DESCRIPTOR,
(LIBUSB_DT_STRING << 8) | idxPrd, 0, buffer, 0xFF, 0);
product = new String(buffer, 2, rdo - 2, "UTF-16LE");
/* int rdo = connection.controlTransfer(UsbConstants.USB_DIR_IN
| UsbConstants.USB_TYPE_STANDARD, STD_USB_REQUEST_GET_DESCRIPTOR,
(LIBUSB_DT_STRING << 8) | idxMan, 0x0409, buffer, 0xFF, 0);*/
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
Log.d("","Manufacturer:" + manufacturer + "\n");
Log.d("","Product:" + product + "\n");
Log.d("","Serial#:" + connection.getSerial() + "\n");
}
}
return strusbName;
}
android获取USB设备的名称的更多相关文章
- C# 获取USB设备信息
C# 获取USB设备信息WMI方式 using System; using System.Management; using System.Text.RegularExpressions; using ...
- Qt 获取usb设备信息 hacking
/************************************************************************** * Qt 获取usb设备信息 hacking * ...
- libusb获取usb设备的idVendor(vid),idProduct(pid),以及Serial Number
发表于2015/6/23 21:55:11 4594人阅读 最近在做关于usb设备的项目,用到了libusb,发现关于这个的函数库的介绍,讲解很少,下面仅仅是简单展示一些基本的使用方法,以备后用. ...
- Android获取手机设备识别码(IMEI)和手机号码
最近看了下获取手机设备ID和手机信息以及SIM的信息例子,主要还是借鉴别人的,现在自己写一下,算是巩固加深了,也希望能给大家一个参考 必要的条件还是一部真机,SIM卡或者UIM卡. 首先,在Andro ...
- android 与usb 设备通信(二)
再次遇到android mUsbManager.getDevicelist() 得不到usb 设备的问题.于是深入去探讨android 与usb 外围设备通信的问题.第一篇文章写的有点乱,本质就是需 ...
- android 获取手机设备品牌
在有些数据要获取手机设备是什么品牌,特别做一些适配的时候,好了就讲下怎样或者手机是什么品牌: String brand =android.os.Build.BRAND; 就这么简单!
- 获取usb设备父系或子代
/// <summary> /// 获取设备父系 /// </summary> /// <param name="driver"></pa ...
- android -------- 获取手机设备信息
最近在开发中,需要用到一些系统信息,总结了一下 /** * Created by zhangqie on 2019/2/26 * Describe: 系统工具类 */ public class Equ ...
- 获取显示设备的名称及PNPDeviceID
实现效果: 知识运用: ManagementObjectSearcher类和ManagementObject类 实现代码: private void button1_Click(object send ...
随机推荐
- sublime 工具
http://blog.csdn.net/admin_yi/article/details/53608965
- MFC命令消息的路由
下面,我们以Menu这个程序为例,来看看 菜单命令消息路由的具体过程:当单击某个菜单项时,最先接收到这个菜单命令消息的是框架类.框架类将把接收到的这个消息交给它的子窗口.即视类,由视类首先进行处理.视 ...
- mina中责任链模式的实现
一.mina的框架回顾 责任链模式在mina中有重要的作用,其中Filter机制就是基于责任链实现的. 从上图看到消息的接受从IoService层先经过Filter层过滤处理后最后交给IoHander ...
- html 文字垂直居中
html 文字垂直居中 <span style="float:right; padding-right:30px;line-height:64px" class=" ...
- thinkphp中url的生成U()方法
为了配合所使用的URL模式,我们需要能够动态的根据当前的URL设置生成对应的URL地址,为此,ThinkPHP内置提供了U方法,用于URL的动态生成,可以确保项目在移植过程中不受环境的影响.U方法的定 ...
- Py修行路 python基础 (十八) 反射 内置attr 包装
一.isinstance 和 issubclass1.isinstance(obj,cls)检查是否obj是否是类 cls 的对象.2.issubclass(sub, super)检查sub类是否是 ...
- Python Twisted系列教程6:抽象地利用Twisted
作者:dave@http://krondo.com/and-then-we-took-it-higher/ 译者:杨晓伟(采用意译) 你可以从这里从头开始阅读这个系列. 打造可以复用的诗歌下载客户端 ...
- 第十二章 MySQL触发器(待续)
······
- 玩转angularJs——通过自定义ng-model,不仅仅只是input可以实现双向数据绑定
体验更优排版请移步原文:http://blog.kwin.wang/programming/angularJs-user-defined-ngmodel.html angularJs双向绑定特性在开发 ...
- 利用jquery mobiscroll插件选择日期、select、treeList的具体运用
体验更优排版请移步原文:http://blog.kwin.wang/programming/jquery-mobiscroll-select-treeList.html mobiscroll是个很好用 ...