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 ...
随机推荐
- 【openCV学习笔记】【2】读取并播放一段视频
#include <iostream> #include <opencv/highgui.h> int main(int argc, char** argv){ cvNamed ...
- CAN总线远程帧和错误帧
远程帧 通常,数据传输是由数据源节点(例如,传感器发出数据帧)自主完成的.但也可能存在目标节点向源节点请求发送数据的情况.要做到这一点,目标节点需发送一个远程帧,其中的标识符应与所需数据帧的标识符相匹 ...
- 使用VS2017 编写Linux系统上的Opencv程序
背景 之前写图像算法的程序都是在window10下使用VS编写,VS这个IDE结合“ImageWatch.vsix“插件,用于调试opencv相关的图像算法程序十分方便.后因项目需要,需将相关程序移植 ...
- java代码List接口和Arraylist类
总结: package clientFrame; import java.util.*; //集合类 List是一个接口.ArrayList是一个类 public class ArraylitTest ...
- java ------------用Array.sort()输出数组元素的最大值,最小值,平均值~~~~
总结:输出最大值,最小值,可以先排序,再输出就容易点了.不用循环判断.我还没学.但是觉得很好用 package com.aini; import java.util.Arrays; import ja ...
- win10 Edge 无法上网代理服务器错误
当连接好网络时 Edge无法上网,提示代理服务器错误,系统其他非第三方软件同样网络异常 解决:为当前所连接的网络更新自动检测 控制面板->网络和Internet->Internet选项-& ...
- 360良心制作fonts.useso.com
我们的网站,经常会用到google的一些数据. 但在国内无法使用google, 360这个良心的企业,解决了这个问题. 把google替换成useso就可以了. 比如, <link href=& ...
- 011. 解决VS2015中CS1528: Expected ; or = (cannot specify constructor arguments in declaration)
编译器错误消息: CS1528: Expected ; or = (cannot specify constructor arguments in declaration) 源错误: 行 94: ...
- IO模型比较分析
异步IO(Asynchronous I/O) Linux下的asynchronous IO其实用得不多,从内核2.6版本才开始引入.先看一下它的流程: 用户进程发起read操作之后,立刻就可以开始去做 ...
- SQL Server Database Backup and Restore in C#
SQL Server Database Backup and Restore in C# Syed Noman Ali Shah, 7 Feb 201 ...