getDeviceList() 始终为空 [英] getDeviceList() always empty

查看:47
本文介绍了getDeviceList() 始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Arduino 板与我的 Odys Neo x8 平板电脑一起使用,但似乎 UsbManager 无法识别该设备.我通过 OTG 适配器将 arduino 连接到平板电脑,以便平板电脑在主机模式下工作,Arduino 成功从设备接收电源.我正在获取平板电脑上可用 USB 设备的列表,如下所示:

I'm trying to use an Arduino Board along with my Odys Neo x8 tablet but it seems, that the UsbManager doesn't recognize the device alright. I connected the arduino to the tablet via an OTG-adapter so that the tablet will work in host mode, the Arduino is successfully receiving power from the device. I'm fetching the list of available USB-devices on the tablet as follows:

sUsbController = new UsbController(this, mConnectionHandler, 0, 0);
        HashMap<String, UsbDevice> devlist = sUsbController.mUsbManager.getDeviceList();
        TextView t = ((TextView)findViewById(R.id.textView));
        t.setText("Found " + Integer.toString(devlist.size()) + " devices");

在类 UsbController 中:

And inside the class UsbController:

mUsbManager = (UsbManager) mApplicationContext
            .getSystemService(Context.USB_SERVICE);

但不幸的是,即使我开始使用 VID 和 PID(两个零)进行过滤,该列表仍然是空的.有关如何解决此问题的任何建议?

But unfortunately, the list remains empty, even if i start filtering using the VID and the PID (the two zeros). Any suggestions on how to fix this?

推荐答案

我使用了以下代码,它在键盘、鼠标和大容量存储设备上都可以很好地与 Pandaboard 连接,

I have used the following code which works very fine with keyboard, mouse and Mass Storage device to connect with Pandaboard,

  UsbManager usbManager = (UsbManager) getSystemService(USB_SERVICE);
  HashMap<String, UsbDevice> devicelist = usbManager.getDeviceList();
  Iterator<UsbDevice> deviceIterator = devicelist.values().iterator();

  while(deviceIterator.hasNext()) {
    UsbDevice usbDevice = deviceIterator.next();
    Log.i(Log_Tag, "Model     : " +usbDevice.getDeviceName());
    Log.i(Log_Tag, "Id        : " +usbDevice.getDeviceId());
  }

这也适用于 Arduino.

This should work with Arduino too.

这篇关于getDeviceList() 始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆