Reputation: 31
I'm trying to communicate with a usb device, using an acer iconia a500 upgraded to android 3.2 (kernel 2.6.36.3+, not rooted, I just used the regular update feature). In a nutshell, what happens is that after I get the UsbManager, getDeviceList returns an empty map. The same happens with the adbtest sample from google:
mManager = (UsbManager)getSystemService(Context.USB_SERVICE);
// check for existing devices
for (UsbDevice device : mManager.getDeviceList().values()) {
// I get nothing here, the values() list is empty
I've tried several devices (various usb solid state disks, an hard drive, a mouse, a garmin watch, etc). nothing. Some devices (disks, mouse) are indeed recognized by the OS (they work: I see the filesystem, the mouse works fine, etc), but they don't get reflected at the API level.
Googling around, some people say that mouse and keyboard don't get enumerated but disks do, but they're using 3.1 while I'm using 3.2. I don't get the disk either, or anything else I've plugged in.
The code above should enumerate all devices. Anyway, I also tried the intent + xml file approach as documented in the google samples. Still nothing.
The manifest seems ok, and as I said, the adbtest sample straight from the sdk shows the same problem.
Given the paucity of the API, I don't really know what to try next. Has anybody succesfully used host mode on an iconia a500 with android 3.2?
EDIT: I mean "used" at the API level. As I said, "standard" devices gets recognized at the OS level and works, but aren't visible through the API. In the end I need to communicate with a non-standard device in host mode, so I really need to get it through the API.
EDIT 2: I'm not contemplating rooting my device because my app (if I ever manage to write it :-) would be useless if rooting was needed.
Thanks!
Upvotes: 3
Views: 2019
Reputation: 623
Try this code,
mUsbManager = (UsbManager) getSystemService(USB_SERVICE);
HashMap<String, UsbDevice> devicelist = mUsbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = devicelist.values().iterator();
if (deviceIterator.hasNext()) {
while(deviceIterator.hasNext()) {
mUsbDeviceX = deviceIterator.next();
if (mUsbDeviceX != null) {
Log.v(Log_Tag, "ProdID: " +mUsbDeviceX.getProductId());
Log.v(Log_Tag, "VendID: " +mUsbDeviceX.getVendorId());
}
}
} else {
Log.v(Log_Tag, "No Usb Devices Attached");
}
If it doesn't work than show us the output of dmesg/logcat here.
Upvotes: 0
Reputation: 3096
Make sure your intent filter is not hiding the devices.
http://developer.android.com/guide/topics/usb/host.html
"In general, use vendor and product ID if you want to filter for a specific device and use class, subclass, and protocol if you want to filter for a group of USB devices, such as mass storage devices or digital cameras. You can specify none or all of these attributes. Specifying no attributes matches every USB device, so only do this if your application requires it:"
Tell me if it works for you.
Upvotes: 2