android ADK - USB OTG (Host mode)

2019-04-02 05:02发布

问题:

I am just starting to get into android soft dev and will be designing accessory hardware to interface the android device. It appears that there are some limitation in what USB modes can be used on the device dependent on the firmware. Based on a documentation on USB from the developer.android.com site. USB host mode is only supported on firmware versions 3.1 and up. However, it appears that the samsung galaxy 2 supports OTG (host mode), at least natively, as demonstrated in this youtube video : SGS2 OTG demo. It is critical that the phone be the host in order to supply a small amount of power to my externally connected hardware.

  1. Can anyone verify whether there is any API access to USB host mode on android mobile phone devices? The reason that I question the android dev quote above is that there is clearly Host mode functionality being demonstrated on the SGS2 phone.

  2. If I cannot access any of the USB host API functionality, is there any way to develop USB peripheral device hardware that can communicate with the phone? It appears that I could design hardware that uses the MSD classes, as appears to be natively supported in the above listed demo?

  3. If there is no API USB host access currently, are there any future plans to add this to mobile phone hardware in the future?

回答1:

A fairly wide variety of device hardware supports usb host (sometimes only partially, without supplying power) but only with alternative firmware or vendor specific extensions - until you get to an API versions where it's an official part of android.

A lot of the videos and web pages you see are people showing off their custom firmware modifications - which can be a path, but one that restricts your market to users willing to mod, a list of devices you certify compatible, or special android devices you sell bundled with your accesory.



回答2:

It is possible to develop applications for the SGS2 that can communicate with custom USB devices.

Firstly, the kernel of the SGS2 implements a whitelist that only allows certain types of device to connect (HID, mass storage, printers, PTP) which means any custom USB hardware that is vendor specific will not be permitted. If you are willing to build your own kernel, or can convince kernel developers to make a modification, the whitelist can be modified appropriately.

Secondly, the USB host classes in the Android SDK are only available in 3.1 but the SGS2 runs 2.3.x, however it will let you build against the appropriate API level and still target the SGS2.

I've written about how to modify the kernel and begin developing an app on my blog.