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设备的名称的更多相关文章

  1. C# 获取USB设备信息

    C# 获取USB设备信息WMI方式 using System; using System.Management; using System.Text.RegularExpressions; using ...

  2. Qt 获取usb设备信息 hacking

    /************************************************************************** * Qt 获取usb设备信息 hacking * ...

  3. libusb获取usb设备的idVendor(vid),idProduct(pid),以及Serial Number

    发表于2015/6/23 21:55:11  4594人阅读 最近在做关于usb设备的项目,用到了libusb,发现关于这个的函数库的介绍,讲解很少,下面仅仅是简单展示一些基本的使用方法,以备后用. ...

  4. Android获取手机设备识别码(IMEI)和手机号码

    最近看了下获取手机设备ID和手机信息以及SIM的信息例子,主要还是借鉴别人的,现在自己写一下,算是巩固加深了,也希望能给大家一个参考 必要的条件还是一部真机,SIM卡或者UIM卡. 首先,在Andro ...

  5. android 与usb 设备通信(二)

    再次遇到android  mUsbManager.getDevicelist() 得不到usb 设备的问题.于是深入去探讨android 与usb 外围设备通信的问题.第一篇文章写的有点乱,本质就是需 ...

  6. android 获取手机设备品牌

    在有些数据要获取手机设备是什么品牌,特别做一些适配的时候,好了就讲下怎样或者手机是什么品牌: String brand =android.os.Build.BRAND; 就这么简单!

  7. 获取usb设备父系或子代

    /// <summary> /// 获取设备父系 /// </summary> /// <param name="driver"></pa ...

  8. android -------- 获取手机设备信息

    最近在开发中,需要用到一些系统信息,总结了一下 /** * Created by zhangqie on 2019/2/26 * Describe: 系统工具类 */ public class Equ ...

  9. 获取显示设备的名称及PNPDeviceID

    实现效果: 知识运用: ManagementObjectSearcher类和ManagementObject类 实现代码: private void button1_Click(object send ...

随机推荐

  1. cpu 核数及逻辑数统计

    查看逻辑CPU个数:cat /proc/cpuinfo |grep "processor"|sort -u|wc -l24 查看物理CPU个数:grep "physica ...

  2. 你知道PING功能是怎么实现的吗

    以太网的协议有层,而每层都包含有更多的协议.所谓协议,通俗的讲就是通信双方约定的规则. 今天我们介绍一些一个听起来陌生却有很常用的协议,ICMP协议. —ICMP是(Internet Control ...

  3. 使用VS2017 编写Linux系统上的Opencv程序

    背景 之前写图像算法的程序都是在window10下使用VS编写,VS这个IDE结合“ImageWatch.vsix“插件,用于调试opencv相关的图像算法程序十分方便.后因项目需要,需将相关程序移植 ...

  4. juc线程池原理(四): 线程池状态介绍

    <Thread之一:线程生命周期及五种状态> <juc线程池原理(四): 线程池状态介绍> 线程有5种状态:新建状态,就绪状态,运行状态,阻塞状态,死亡状态.线程池也有5种状态 ...

  5. Centos 6.5 安装Oracle 11g R2 on vbox

    由于上一篇的rac安装,截图较多,这一篇选择以txt的方式叙述,另外上一篇的时间比较久远,这里最近从新安装 --2018-10-29 1 os环境初始化 [root@rac1 yum.repos.d] ...

  6. python学习(十一) 文件和流

    11.1 打开文件 >>> f = open(r'c:\text\somefile.txt'),  第一个参数是文件名,必须有:第二个是模式:第三个参数是缓冲. 11.1.1 文件模 ...

  7. 阻塞IO(blocking IO)

    在linux中,默认情况下所有的socket都是blocking,一个典型的读操作流程大概是这样: 当用户进程调用了recvfrom这个系统调用,kernel就开始了IO的第一个阶段:准备数据.对于n ...

  8. 什么是闭包?在js中的作用是什么?

    闭包就是讲函数内部生成的变量保存到内存中,进行下次调用:也可以说函数外不可以调用函数内部的变量: 当函数内部返回一个函数时,闭包搭建了方法内部与方法外部的桥梁,使得外部也可以任意的获取到方法内部的资源 ...

  9. PHP判断当前协议是否为HTTPS

    function is_https() { if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'o ...

  10. oracle10g Error in invoking target 'install' of makefile

    oracle10g series error error in invoking target 'install' of makefile /u01/app/oracle/oracle/product ...