Android to PC USB Read/Write

11,928

I'm not sure I exactly follow what you're doing here, but if I understand you correctly - it just won't work this way. The UsbManager.getDeviceList() is meant to be used with Android devices with USB host port, to which some USB devices are connected. But, as far as I understand, you connect Android tablet acting as a device to your PC acting as a host (I guess so, cause you wrote about driver installation).

If you want to communicate between Android USB device and some USB host (e.g. because your Android device has no USB host capabilities), you need to use accessory mode (I suggest you start with this Android Developers Blog post). But this mode requires special support on the USB host side (it must talk to the device with Android Open Accessory Protocol). Note, that getDeviceList() makes no sense in Accessory mode - first of all, connected accessory is a USB host, not a USB device, and there can be only one USB host on a USB bus.

If you want to communicate with PC using Accessory mode, you may want to try this AOAP implementation for PC. If all you need is to talk to Android device for some debugging needs, you may want to use ADB port forwarding and TCP connection instead.

Share:
11,928
Sawant
Author by

Sawant

Updated on July 19, 2022

Comments

  • Sawant
    Sawant almost 2 years

    I have a program on PC taking in string input from USB ( old program) I have a Android (4.X) tablet which needs to provide string input on USB to the program running on PC. When I used the sample code on Android, following code gives empty hashmap. The PC( tried on 32 bit XP and 64 bit Windows 7) has Android driver.

        mManager = (UsbManager)getSystemService(Context.USB_SERVICE);
        HashMap<String, UsbDevice> devices =  mManager.getDeviceList();
    

    Any real working code example talking to PC over USB will help, pl. also point out if any driver etc. needed on Android to talk to PC.

    I have tried both the Accessory mode and the host mode( just in case)

  • Sawant
    Sawant over 11 years
    Hi Code Painters , Thanx for the answer , You are right , it is actually the UsbManager.getAccessoryList() call but that returns Null;
  • Sawant
    Sawant over 11 years
    Hi @Code Painters , Thanx for the answer , My Manifest is set up in Accessory mode. Followed the documentation .You are right , it is the UsbManager.getAccessoryList() call but that returns Null too .I am working on Android 4.0.3 so I am using the android.hardware.usb.accessory at API level 15. I am debugging on tcp/ip with a coby kyros with usb debugging mode enabled , but it just does not recognise any accessories (i.e) Windows host Laptop connected to the android coby thru a usb cable. I tried runn'g the app without the debug'r with the usb debug'g mode off , still returning null.
  • Code Painters
    Code Painters over 11 years
    For the Windows laptop to be recognized as an accessory, you need some implementation of accessory protocol running on it, see the link in my answer.
  • Shubham Agrawal
    Shubham Agrawal over 4 years
    @CodePainters Can you let me know how can this be implemented with some code in Android and Server Side or a link to a blog.