Monday, December 3, 2012

[android-developers] Re: Nexus 7 USB Host - Not able to enumerate device

If the device appears in "USB device info" Android tab that means that it WILL appear in your app. Because "USB Device info" uses USB Host to detect devices.

On Monday, October 29, 2012 8:06:45 AM UTC, al wrote:
HI,

first: USB-Host including the USB-Host api works for me on the Nexus 7 - no root required.

You could try an app like "USB Device Info" to validate your hardware setup (usb adapter etc.).

I have setup intents and filters, but I also assume they are not necessary if you scan for devices yourself.
As I understand it, you just tried a mouse and a phone? I just made a test with a mouse and though "USB Device Info" saw it on the "linux" tab, it did not see it on the "android" tab. My app also did not see the mouse. I assume since android handles the mouse itself, it does not make it visible to the app.

I.e. try another usb device. If you can see it on the Android tab in "USB Device Info", you probably should see it in your app.

Am Sonntag, 28. Oktober 2012 23:41:04 UTC+1 schrieb Kiran:
Hi All,
I recently bought a Nexus 7 for USB development.  I would like to use the USB Host functionality provided by the new Android OS.  I was following the USB Host Tutorial at the link: http://developer.android.com/guide/topics/connectivity/usb/host.html.

My program is very simple, and here are the relevant parts of the code:

    private UsbManager manager;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Log.i(TAG, "in onCreate()");
        manager = (UsbManager) getSystemService(Context.USB_SERVICE);
        if(manager==null) {
        Log.i(TAG, "USB Manager is NULL");
        }
        else {
        Log.i(TAG, "USB Manager = " + manager);
        }
    }
    
    public void enumerateUSBDevices() {
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Collection<UsbDevice> deviceCollection = deviceList.values();
    Iterator<UsbDevice> deviceIterator = deviceCollection.iterator();
    Log.i(TAG, "Number of connected USB Devices = " + deviceCollection.size());
    while(deviceIterator.hasNext()){
       UsbDevice device = deviceIterator.next();
       Log.i(TAG, device.getDeviceName());
    }
    }


When the enumerateUSBDevices function is called, it reports that the number of connected USB Devices = 0.  I am using a USB OTG cable, and I know that the Nexus 7 is powering the connected USB Device because I plugged in a USB Mouse, and it works properly.  I also plugged in another Android phone, and the Nexus 7 was confirmed to be powering the device.  However, in both of these instances, the Android program says that there are no USB devices connected.  I am unsure what is going wrong in my code.  In my Android manifest, I have the following line:

<uses-feature android:name="android.hardware.usb.host" />

My manifest does not have any intent filters associated with any USB devices.  My understanding based on reading the tutorials is that the intent filters need to be in the Manifest only if you want the APP to be notified when the USB device is connected after the App is running?

Can anybody shed light into what I may be doing wrong?  Do I need to root my device?

Thanks,
Kiran

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment