Android USB设备-UsbManager赢得';列举

Android USB设备-UsbManager赢得';列举,android,Android,我正在将一个我自己制作的USB设备(dsPIC33E供电)连接到一个通用的7英寸A13-MID安卓系统 我正在使用ADB over TCPIP并运行LogCat 当我插入设备时,我在LogCat中得到: I/USB3G (90): event { 'add', '/devices/platform/sw_hcd_host0/usb1/1-1', 'usb', '', 189, 7 } I/USB3G (90): path : '/sys/devices/platform/sw_hcd_host0

我正在将一个我自己制作的USB设备(dsPIC33E供电)连接到一个通用的7英寸A13-MID安卓系统

我正在使用ADB over TCPIP并运行LogCat

当我插入设备时,我在LogCat中得到:

I/USB3G (90): event { 'add', '/devices/platform/sw_hcd_host0/usb1/1-1', 'usb', '', 189, 7 }
I/USB3G (90): path : '/sys/devices/platform/sw_hcd_host0/usb1/1-1'
I/USB3G (90): VID :size 5,vid_path '/sys/devices/platform/sw_hcd_host0/usb1/1-   1/idVendor',VID  '04d8'.
I/USB3G (90): PID :size 5,Pid_path '/sys/devices/platform/sw_hcd_host0/usb1/1-1/idProduct',PID  '003f'.
I/USB3G (90): cmd=/system/etc/usb_modeswitch.sh /system/etc/usb_modeswitch.d/04d8_003f &,
I/USB3G (90): excute ret : 0,err:No such file or directory
我已经在调试模式ADT下运行了MissileLauncher演示

我可以在Fire中设置一个断点,当我按下Fire按钮时,代码在那里中断(因此调试正在进行)

我已在device_filter.xml中将产品ID和供应商ID设置为正确的值

然后我在这里设置了一个断点:

UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
    setDevice(device);
} else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
    if (mDevice != null && mDevice.equals(device)) {
        setDevice(null);
    }
}
当我在中断后单步执行代码时,将执行intent.行,但未输入以下if语句,并且从未调用
setDevice(device)
(setDevice(null))

我确实希望调用setDevice(device)。毕竟,我已经插入了设备,android看到我插入了它(见上面的LogCat),并且我已经正确设置了设备_filter.xml

我错过了什么

其他信息,我安装的一个应用程序“USB设备”看到了这个设备,但在Linux标签下列出了它。我希望这对我来说不是坏消息

谢谢, 戴尔

我试图逐一列举设备,但没有“是”(事实上HashMap中没有返回任何设备):

HashMap deviceList=mUsbManager.getDeviceList();
迭代器deviceIterator=deviceList.values().Iterator();
while(deviceIterator.hasNext()){
UsbDevice device1=deviceIterator.next();
//你的代码
如果(device1.getVendorId()==1240){
savetofile(“耶!”);
}
} 

不确定这是否相关,但安卓系统是根目录的,它就是这样来的。

结果表明,我需要使用根目录权限,并在回答的问题中进行更改:

我走上了正确的道路,现在我是:)再次。我相信其他人会发现我寻求这个答案的努力很有帮助

但是,只有HashMap枚举方法起作用,intent filter方法仍然以android.intent.action.MAIN的形式返回操作

谢谢你的意见


Dale

什么在起作用?你检查了吗?@njzk2 action“android.intent.action.MAIN”(id=83001334544)count 26 hashCode-1173447682偏移量0值(id=83001334576)这就是为什么。你没有收到ACTION\u USB\u DEVICE\u*@njzk2抱歉,我是个新手,这意味着什么?有没有办法解决这个问题?你是如何得到这个代码的?你正在启动一项服务或其他什么?是的,这就像一个符咒(micromax A120手机,kitkat 4.4.2)。请参阅评论。
HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext()){
    UsbDevice device1 = deviceIterator.next();
    //your code
    if (device1.getVendorId()==1240) {
        savetofile("Yeah!");
    }
}