USB_DEVICE_ATTACHED意图不触发 [英] USB_DEVICE_ATTACHED Intent not firing

查看:432
本文介绍了USB_DEVICE_ATTACHED意图不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人在那里能够得到的android.hardware.usb.action.USB_DEVICE_ATTACHED工作?

Has anyone out there been able to get the android.hardware.usb.action.USB_DEVICE_ATTACHED" to work?

好了,所以我想要使用新的USB主机模式的功能,以检测当USB设备连接。对于我而言,我想通知设备连接的任何时间。我没能看到这一点。我使用的是广播reciever,我知道作品(当我有它监听其他的东西,如pssed主页按钮时$ P $。无论我怎么努力我似乎无法得到的意图火... 。因此,为了使事情变得更简单,我决定忘记我的项目,并尝试使用谷歌自己的样品code,看看我至少可以做这项工作。我没有导弹发射器之一,但我想我可以至少得到它的USB_Device_Attached火灾。没有去。我适应了code,以适用于其他设备。开始我尝试调整装置过滤器的XML。 我说我的设备(键盘):

Ok so i'm trying to use the new usb host mode features to detect when a usb device is attached. For my purposes i want to be notified any time a device is attached. I was not able to see it happen. I'm using a broadcast reciever that i know works (when i have it listen for other things such as the home button being pressed. No matter what i try i can't seem to get the intent to fire.... So to make things simpler i decided to forget about my project and attempt to use google's own sample code and see if i could at least make that work. I don't have one of the missle launcher but i figured i could at least get it the USB_Device_Attached to fire. No go. I adapted the code to work for other devices. First i tried adjusting the device filter xml. I added my device (a keyboard):

<usb-device vendor-id="1050" product-id="0010" />

我接到一个命令的lsusb的供应商和产品。当设备被安装在的logcat显示该设备发现

I got the vendor and product from an lsusb command. When the device is attached the logcat shows that the device is found

D/EventHub(  144): No input device configuration file found for device 'Yubico Yubico Yubikey II'.
I/EventHub(  144): New device: id=43, fd=219, path='/dev/input/event8', name='Yubico Yubico Yubikey II', classes=0x80000003, configuration='', keyLayout='/system/usr/keylayout/Generic.kl', keyCharacterMap='/system/usr/keychars/Generic.kcm', builtinKeyboard=false
I/InputReader(  144): Device added: id=43, name='Yubico Yubico Yubikey II', sources=0x00000101
I/ActivityManager(  144): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/1 nav=1/2 orien=L layout=0x10000014 uiMode=0x11 seq=47}
D/MissileLauncherActivity(16191): intent: android.intent.action.MAIN
I/EventHub(  144): Removed device: path=/dev/input/event8 name=Yubico Yubico Yubikey II id=43 fd=219 classes=0x80000003
I/InputReader(  144): Device removed: id=43, name='Yubico Yubico Yubikey II', sources=0x00000101
I/ActivityManager(  144): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=1/1/2 nav=1/2 orien=L layout=0x10000014 uiMode=0x11 seq=48}
D/dalvikvm(  144): GC_EXPLICIT freed 78K, 26% free 14717K/19719K, paused 3ms+3ms
D/MissileLauncherActivity(16191): intent: android.intent.action.MAIN

Xoom的确实发现键盘,它是从设备(我可以用它在浏览器中键入字母)可用。而意图排序火灾(但它只激发android.intent.action.MAIN)的我从来没有得到DEVICE_ATTACHED意图。该日志条目来自样品code:

The xoom does find the keyboard and it is usable from the device (i can use it in the browser to type letters). And the intent sort of fires (but it only fires the android.intent.action.MAIN) i don't ever get the DEVICE_ATTACHED Intent. The log entry comes from the sample code:

Log.d(TAG, "intent: " + intent.getAction().toString());

在恢复功能。经过挖掘和删除任何引用USB我发现,每一个应用程序我做的GET时调用键盘连接/分离简历(因此意图:android.intent.action.MAIN日志条目)。     眼下我唯一能数字是,它是在Android源代码中的错误。 顺便说一句,我使用与OS 3.1一个WiFi XOOM。

In the resume function. After more digging and removing any reference to usb i found that every app i make get's the resume called when a keyboard is attached/detached (hence the intent: android.intent.action.MAIN log entry). Right now the only thing i can figure is that it's a bug in the android source. By the way i'm using a wifi xoom with os 3.1.

推荐答案

我也有同样的问题。我终于想通了,在设备筛选器的XML,我们应该添加以下行。

I also had the same problem. I finally figured out that in the device filter xml we should add following line.

<usb-device vendor-id-"xxxxx" product-id="yyyyy">

在XXXXX和YYYYY应该是小数。不是十六进制codeS。然后一切都像宣传的那样! 我知道这是晚了,但我希望它能帮助。

the xxxxx and yyyyy should be decimal numbers. NOT HEX CODES. Then it all works as advertised! I know it is late but I hope it helps.

这篇关于USB_DEVICE_ATTACHED意图不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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