I have a USB device and want to build a nice graphical interface for it. Is it possible to connect the USB device to Android, have Android be the host, and communicate with it and build a UI? If so, which libraries would allow me to do this? And if not, what alternative workarounds are there? I would prefer a wired connection for reliability.
It's possible. I have personally used an USBc to USB cable to hook up everything from a keyboard and mouse to an external monitor. Some phones/devices may not have a data port on the external USB port or the chips needed for external monitors but android itself has USB drivers built in.
I think this question remained unanswered for so long because it's so easy to google the android developer page that should answer your question in specifics here. It's the developer guide for using android as a USB host.
Related
I've started a project on Andorid, but I don't know NDK very much. I want to send custom data as per receiving message on usb port. I saw some applications that can send/recieve custom data on usb port if the phone is in recovery. I've programmed usb connection in windows before. But I haven't any clue where should I start in android. Is there any documentation for usb programming for android? If NDK isn't suitable to implement this, which options do I have? It is not important if the application is device specific.
The issues are more of system architecture and permission, an area where the NDK offers little in excess of the SDK.
Android does not really support (direct) custom use of the USB port, at least when the device is connected to a computer (there are some recent options when the device is hosting a USB peripheral). What is possible in recovery mode is essentially irrelevant, unless you want to make substantial modifications to the installation of Android running on your device.
Generally, the only practical way to do application-level communication between the device and a hosting PC is to use the IP networking paradigm over the USB cable. You do this either by enabling USB debugging on the device and installing much of the android SDK on the PC, or by enabling some forms of tethering which may create a general network as a side effect.
For the SDK method, read up on adb port forwards, including the limitation that the PC side must initiate the connection.
It may also be possible to create custom drivers which get a PC to pretend to be an android accessory kit (ADK) circuit and use the apis related to that.
Unfortunately, pretty much all of these ideas are more suitable for developers/power users, than for general consumer application. For consumer apps, most developers ignore the USB cable and do IP networking over WIFI, requiring the user to put the device and the PC on the same network, or proxy through an Internet server visible to both the PC and the device's mobile network.
I am a relatively new Android developer but have gotten pretty familiar with the SDK, using LogCat, etc. However, I'm now working on an app (for a Galaxy Tab 7-plus) that utilizes USB Host mode to talk to an external USB device and I've run into an issue.
My question is: What is an ideal environmental setup that will allow me to take advantage of all of the SDK tools (adb, debug, LogCat, DDMS, and so forth) when I am unable to be connected to my PC via USB (since the external USB device my tablet is talking to is using my tab's only USB port)?
Is there an emulator available somewhere (I've searched in vain) that will allow me to simulate USB Host mode using a USB port on my PC?
Do I need to go to some type of on-board logging app?
Is there some kind of 30-pin splitter available so I can connect to both the external device and my PC? (I'm guessing this is impossible, but I'm a hardware idiot... in addition to a run-of-the-mill idiot).
Thanks in advance for your help!
-KR
As I posted in the comments, If the tablet is rooted you can use AdbWireless (Application on the Market)
This can also be done without rooting. Google/Android officially supports this, as described at the bottom of this page:
http://developer.android.com/guide/topics/usb/index.html
But AdbWireless is easier if you are rooted.
Does anyone know how to configure an Android device (tablet) to appear as a USB HID device when connected to a PC?
Is there any other way of getting data from the tablet to the PC (via USB) other than writing it to a file, and have the PC retrieve the (updated) file from the tablet which is acting as a 'mass storage device' for the PC?
Can USB carry a TCP/IP end-end connection?
Using a tablet as a high-end intelligent 'keyboard' or 'mouse' or similar device would be immensely powerful, and open up lots of possibilities. Controlling a model railway layout is the end I have in mind.
Thanks
It's possible to do this using the linux gadget framework http://www.linux-usb.org/gadget/ using a custom composite USB device. The gadget framework is part of the Android kernel source tree by inheritance from Linux.
Unfortunately, Android has its own customizations that restrict the ability to dynamically register new USB gadgets so you will need to patch the kernel source tree for your particular device and add your HID gadget (otherwise you could create a module and load it that way) to the supported Android list.
I have done this before and will update this answer to contain more detail if there is interest. Unfortunately I lost the code so I will have to start from scratch.
If I set up a web server on my phone and enable usb tethering, I can access that server from my PC. If that's not enough for you, this might help: https://market.android.com/details?id=usbwebcam.application&hl=en
I'm running cyanogenmod on a Desire CDMA (BravoC)
Let me know what you find out; it would be pretty handy to use my phone as a USB keyboard in the field. An android server with a PC client is gonna be easiest though.
Have a look at Android Open Accessory Protocol 2.0. This could help you out.
I've been able to find a few posts on StackOverflow about how to control USB devices using an Android phone -- which I understand is impossible (The Android being a USB device and all.)
However, I would be perfectly happy to set up my application to communicate with the other computer (a Linux host) as a USB device. (Like a really expensive mouse...)
Does anybody have information about how to set up an Android app/phone to use the USB connection and exchange data with a host computer. Obviously, it already works at some level -- it's how Eclipse and Android SDK/debugger do what they do, but I'm still looking for some way to do this in an application.
(My current phone, BTW, is a Droid Incredible.)
Thanks,
R.
Basically you'd need to install the USB device driver and the ADB toolsuite from the SDK, either that or reverse engineer their functionality and build it into something else.
Then you enable USB debugging on the phone.
And then you can do something like an adb port forward to allow an application on the pc to connect to a network socket listener on the phone. Note that connections cannot be made in the other direction, but once a connection is made it is bidirectional.
If your version of android supports tethering over USB, you could also leverage that to implicitly create a network between the PC and the phone, at which point you can make connections in either direction. Just make sure nothing starts accidentally pumping lots of data through the phone's mobile network!
(Many android phones actually can experimentally function as USB hosts, but you have to compile new drivers into the kernel, install the new version, and make up a cable to provide USB power to the device as the phone cannot. Also you lose the ADB over USB channel which makes debugging a pain)
What would be the best way to access the USB as a serial port on an Android device (HTC Magic)?
I am thinking about an OBD-II interface. Can I do this on a standard phone or more likely will I need a modified firmware?
According to this post, Matt Porter presented a review of Android at the Embedded Linux Conference Europe. I mention this mostly because of the example used to describe the current state of Android.
"Just one more practical example: You cannot even plug a USB drive to an android system, since /dev/sd* is not an expected device name in their hardcoded hotplug management.
Executive summary: Android is a screwed, hard-coded, non-portable abomination."
I'm sure someone's working on it, but I'm afraid for now you're out of luck unless you're willing to go low-level and edit the OS.
PSFreedom (project to jailbrack Playstation 3) has list of controllers which support usb host mode which then translate to supported Android devices.
My own expirience is that usb host works on HTC Dream/G1 without problems.
For OBD-II I would suggest bluetooth ODB-II dongle which side-stepps problem with usb host adapter.
Depending on the USB chip in your particular phone, it may be possible to rebuild the kernel to support USB Host mode or USB On-The-Go (Host + Gadget modes) instead of the normal USB Gadget mode. I've found some people speculating that it could be possible on the HTC Dream. Assuming you could reconfigure the USB port in Host mode a USB to serial, ODB-II, or CAN should be doable.
From what I can tell Android is Linux of some sort, to have USB device which would apear as serial port, you should write a driver for that device. I don't know much about OBD-II interface but i am guesing they use some sort of USB driver for windows, same is for android, not mentioning the application to handle the driver.
I don't think the current Android devices can act as a USB host only as a USB device when attached to a host. So using the USB port as a serial port is not likely.
Get a hostmode kernel for your device and you can use python for android and the pyserial library to talk to the serial over USB. I did this with Huawei Ideos U8150 (here is the post) for a loopback test.