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 ...
随机推荐
- 【转】使用Jmeter录制web脚本
1.web性能测试以及web http请求基本原理. 再介绍录制jmeter脚本之前,我们先谈一下web性能测试.web就是调用http/https接口, 其实没有是什么复杂度可言.只是我们必须清楚, ...
- 校赛热身赛 Problem D. Unsolved Mystery
Problem D. Unsolved MysteryThe world famous mathematician Wang Hao published a paper recently in the ...
- Java中静态变量、静态代码块、非静态代码块以及静态方法的加载顺序
在研究单例设计模式的时候,用到了静态变量和静态方法的内容,出于兴趣,这里简单了解一下这四个模块在类初始化的时候的加载顺序. 经过研究发现,它们的加载顺序为: 1.非静态代码块 2.静态变量或者静态代码 ...
- git版本控制-详细操作
- git,软件帮助使用者进行版本的管理 阶段一git 命令: git init 初始化 git config --global user.email "you@example.com&qu ...
- linux 混杂设备驱动之adc驱动
linux2.6.30.4中,系统已经自带有了ADC通用驱动文件---arch/arm/plat-s3c24xx/adc.c,它是以平台驱动设备模型的架构来编写的,里面是一些比较通用稳定的代码,但是l ...
- FPGA SD 卡 之 乒乓操作 、同步fifo
这里记录一个实际的需要使用乒乓操作的例子:读sd卡数据的时,在spi的模式下.发送单数据块的读取命令,在回应之后会有 512字节的数据.使用乒乓操作,可以用两个八位的寄存器,就可以完成连续的512字节 ...
- mysql跟踪执行的sql语句
修改my.cnf配置文件 /usr/local/mysql/bin/mysql --verbose --help | grep -A 1 'Default options' Default optio ...
- 各大IT/IC公司offer比较
1:本人西电通院2013届毕业硕士,根据今年找工作的情况以及身边同学的汇总,总结各大公司的待遇如下,吐血奉献给各位学弟学妹,公司比较全,你想去的公司不在这里面,基本上是无名小公司了:但无名小公司有时也 ...
- 【原】Coursera—Andrew Ng机器学习—Week 2 习题—Linear Regression with Multiple Variables 多变量线性回归
Gradient Descent for Multiple Variables [1]多变量线性模型 代价函数 Answer:AB [2]Feature Scaling 特征缩放 Answer:D ...
- @RequestParam注解的作用
1.这个注解是干什么的??? 提取和解析请求参数的能力. 2.实例解析: a.代码 @Controller @RequestMapping("/pets") @SessionAtt ...