2013-01-16 43 views
2

我我建了一個USB設備(供電的dsPIC33E)連接到普通7" A13-MID安卓USB設備 - UsbManager就不一一例舉

我使用ADB在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 

我已經MissileLauncher演示在調試模式下運行ADT

我可以在火災中設置斷點,當我按下開火按鈕,代碼打破了(所以調試工作)。

我已將Product-ID和Vendor-ID設置爲device_filter.xml中的正確值。

我然後設置一個斷點位置:

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); 
    } 
} 

當我通過代碼突破後,意圖。行被執行,但是下面的if語句沒有被輸入並且setDevice(device)從不被調用(既不是setDevice(null))。

我的確希望setDevice(設備)被調用。畢竟,我有設備插入,android看到我插入(參見上面的LogCat),並且我正確設置了device_filter.xml。

我錯過了什麼?

其他信息,我安裝的'USB設備'的應用程序看到設備,但列在Linux選項卡下。我希望這對我來說不是壞消息!

感謝, 戴爾

我試過單獨列舉的設備,但沒有「呀」(其實沒有設備在HashMap中返回):

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!"); 
    } 
} 

不知道這是相關的或不是,但android是根深蒂固的,它就是這樣。

+0

什麼是行動?你檢查了嗎? – njzk2

+0

@ njzk2 \t action \t「android.intent.action。MAIN」(ID = 830013334544)\t \t計數 \t的hashCode \t -1173447682 \t \t偏移 \t值\t(ID = 830013334576) – KiloOne

+0

這就是爲什麼你沒有收到ACTION_USB_DEVICE_ * – njzk2

回答

0

原來,我需要使用root權限,讓我在這個發現的變化回答問題:

Android USB host and hidden devices

我是在正確的軌道上,現在我再次:)。我相信別人會發現我的任務是尋找這個答案有幫助。

但是,只有HashMap枚舉方法起作用,intent過濾器方法仍然將action作爲android.intent.action.MAIN返回。

感謝您的輸入!

戴爾

+0

是的,這工作像一個魅力(micromax A120手機,kitkat 4.4.2)。請參閱評論http://stackoverflow.com/a/11992683/979369。 – mahesh