Is it possible to communicate between two android devices connected together via USB. This is assuming they are both devices with USB OTG and have kernels that support it.
I've tried searching for this but cannot find a good starting point. I'd assume that one of the devices needs to act as a host and one as a client which is exactly what I need (only really require one way communication actually).
I tried connecting two phones (one running ICS and the other JB) using a male-A-to-male-microB cable coupled with a female-A-to-male-microB adapter, and one of the phones detected the other one as a USB device.
Whether I'd actually be able to communicate between them somehow is a different matter. Perhaps the Android developers documentation on this subject could be of some help.
You can use mobodaemon for android.
Related
I am in the planning stages of a project and potential issue has come up and I can't find the answer.
I am going to use a raspberry pi 4 with Android installed. To achieve my goal I will have to use a Bluetooth USB adapter with an external aerial. Because the raspberry and pi already has an onboard Bluetooth module, how will the OS cope with a second module being plugged in?
Can I disable the on board Bluetooth or force Android to use a particular module exclusively e.g the usb module?
Thanks
Unfortunately this is either not doable or at least not straight-forward. The reason is that the Android OS was designed to have one adapter only that does the Bluetooth functionality (as can be seen here and here). Even if you find a way to do it on the OS level, I would personally advice against it as there's very little resources on how that is done and you might soon find yourself stuck on another issue.
Is there a reason why you wouldn't use Linux and the BlueZ stack instead? There are many resources and examples on how to do this and with BlueZ and you should be able to use multiple adapters without an issue. If using Android is a must, then another recommendation is to use another MCU to connect to the Bluetooth dongle and do the translation from BT/USB and then have the Raspberry Pi connected to the external MCU over USB.
Below are a few links with people having a similar problem:-
How to use two Bluetooth adapters in Android
Are multiple Bluetooth adapters under Android possible
If the Android version doesn't matter, there's even AOSP BlueZ for Android.
I wanted to make an RPG for Android 2.3 Mobile Phone and thought that the good old Gameboy had the perfect format for such games. So I want to build a "Case" with a D-Pad and a few keys and connect them with the Android Device over USB. I don't want Bluetooth, because it needs to much energy. I thought about giving the Case its own Battery Cell and maybe loading the Android Device with it. So my Question is:
How can I access the Keys of this Case from the Android Device?
You might consider the Android Open Accessory Development Kit.
Even if you don't want to buy the ADK, the above link has information that will be useful to you in developing an interface to your accessory. In particular, the section on implementing the accessory protocol and the following section on how the ADK implements the protocol should prove informative. In addition, you'll probably want to look at the USB Accessory link which contains a section concerning communication with an accessory.
You can use USB on devices that have a host USB port unfortunately, not many devices have this. Your other options are bluetooth or wifi both can be accomplished in a multitude of ways. If you Google Arduino + Android I believe you will find examples of people connecting hardware to Android devices via Arduino. This is not the only way to do it, just an example of one way you could do it.
Android USB documentation
http://developer.android.com/guide/topics/usb/index.html
EDIT
You, could I suppose, use Arduino as the USB host also and use accessory mode on the Android end. In any case this none of these options are incredibly straightforward and you will need to do a lot of research to accomplish what you are envisioning.
I'm trying to make an app on an Android device that will control an application on an iPad or Android tablet. (I'm testing with an Samsung Galaxy S2 and an iPad 2).
The application is pretty simple for now. When one selects a colour on the Android mobile, that colour displays on the tablet device.
The question is, how to connect the two devices. Just now I've verified that I can pair the two devices using Bluetooth. Also, the Samsung has a "Kies" Wifi Direct feature (which I don't understand fully), that allows the iPad to connect to the Galaxy as a wifi hotspot.
The connections are there, but I don't know if either protocol can be used to actually get the apps to talk to each other to get the control I'm looking for.
Should I be using Bluetooth, Wifi, or something else?
And in whichever case, how?
My opinion is that you should not stick so much around the physical medium used for connectivity either is WiFi or Bluetooth. You should abstract this aspect, in both cases you will be using sockets (I'm speaking about Android), if it's Bluetooth you will be using Bluetooth Sockets, if it's WiFi: TCP sockets. You could have a intermediate layer that abstracts the type of connection and through a factory to use either Bluetooth or TCP.
Bluetooth - http://developer.android.com/guide/topics/wireless/bluetooth.html
For WiFi you should study if P2P would help.
You will need two applications:
- one on the tablet - the server which listens for commands from the client (change color, do this or this)
- second on the smartphone - the client which sends commands.
I've built a few apps that do exactly that between iPhone and iPad. But the principle is the same. I used Bonjour networking. It's just a fancy name for ZeroConfig networking between devices. It's written originally by Apple but it's open source so there should be Android support out there for it too. Really simple and easy to work with.
If you already have a working connection then you already have the first half of your answer, that said you should really consider implementing a solution that uses a variety of connection types, WIFI, Bluetooth, etc.. The question I think you are really asking is how to pass data and messages between the apps once you have the connection.
There are a lot of ways to accomplish this. You could implement your own lightweight message passing system. If you haven't done this before it is more complicated than it originally seems, especially as you would be required to implement the system for each OS you end up using.
Should I be using Bluetooth, Wifi, or something else?
It depends on what situations you want your program to work in.
Bluetooth can provide a direct connection between your devices. A potential issue with bluetooth is that it has a limited range. If you're devices need to be far away from each other, you may want to go with wifi. Otherwise, bluetooth could work great.
If both devices are connected to the internet, you can make them talk to each other through there. The advantage of this approach is that it doesn't matter how far apart your devices are as long as they're both online. A disadvantage is that you'll have to figure out how to find the tablet's ip address before you can talk to it. This is actually a HUGE disadvantage because it can be quite problematic if both of your devices are not on the same wifi. You could have the user type in the destination ip address, but you'll have problems getting it to work if the user is behind a router (which will almost always be the case). The point is, it gets hairy.
If both of your devices are on the same wifi, you can use ZeroConf AKA bonjour (like Dancreek said) to figure out what ip address you need to send info to. I've previously used a library called jmdns (easy to find with google) to implement zero configuration networking. It's good because the user doesn't have to worry about ip addresses... it's intuitive for the user.
And in whichever case, how?
Networking is a pretty big topic, so I can't expand on this question to much. Short answer is, it depends on what method you choose. Search for some tutorials and start by getting one of your devices to send something as simple as an int to the other.
From a year ago, Is there a way to communicate with USB devices on Android? this didn't look like a common requirement, but tablets have evolved, and hopefully, the OS has, as well.
I need to operate a simple USB relay card from my Curtis LT8025 tablet, currently running 2.1 patched.
I'm also a newcomer to both Android and java, so relatively clueless!
No need for bi-directional communication, just a simple serial command out to the device.
Any suggestions?
Thanks!
Dave
Sadly, there is currently no standard API to achieve wired communication with Android devices. I was facing a similar issue a while back (see Android: Communicating with a USB device which acts as host ).
I was able to successfully implement the solution provided by CommonsWare. Leave a comment if you need more help regarding this and I can provide details.
Edit (more details) -
Basically, I narrowed down to two possible solutions for this problem:
Modify the Android source itself to include custom drivers for whatever purpose you need and install this in your tablet. Since its mostly based on Linux, if you develop the drivers for Linux, the same can be used in Android with a little modification. This solution is simpler to develop, but not practical commercially if you are not providing the tablet/phone yourself.
Make your USB device act as an host and implement the ADB driver/command-set in your device. When connected, you can issue "adb forward" to forward tcp ports so you can interact with your Android apps and have two way communication between the device and the app.
I used the second method and it works flawlessly. But its only practical if you are making USB host devices. for USB slaves, first method is the only way I recon.
If you are using a serial device and have the ability to talk to it over native serial, you might want to consider IOIO (see http://ytai-mer.blogspot.com/2011/04/meet-ioio-io-for-android.html for more details).
I'm building an Android custom system. I did connect several devices on the USB. I looked to connect a device on the OTG port, the one that usually gets out of a tablet on which you use ADB. I gave up. This is a nightmare. I don't think you can use ADB on the OTG USB that is currently a device and expect to be able to use another device like a USB to serial converter. That means that you loose the whole ADB toolchain for debugging when you want to use the port as a host. On top of that, the USB OTG drivers you have for your tablet was probably not very well tested in host mode since it's not really used that way. So lots of headakes.
The simple way that I found was to use the second USB port on the CPU. This one is a plain HOST port (unfortunately limited to 12 Mbit/s). Unfortunately, I don't know if there are any tablet out there with 2 USB port available from outside (One OTG and one host).
If you get a set-up with two USB port (one HOST) then it's possible to compile as a module (drivername.ko), a usb to serial converter. There are several chipset supported in the kernel source tree and I already used a few of them and it works.
hope this bit of info is helpful.
OK, so i have seen all the stuff about how acting as a USB host is impossible on vanilla android, but is there anything in the Android API that would allow an app to override the default USB behavior in order to manually control the USB i/o responses, in order to support some other protocol? I have not seen anything that would facilitate this, but is it possible without hacking the kernel?
This seems like the sort of thing which should be relatively easy, but i haven't found anything. Forgive me if i've been googling incorrectly.
I believe that the stock kernel does not include the correct drivers for this. You need to be able to root your device and you need one of the devices capable of acting as a USB host.
See this page, http://sven.killig.de/android/N1/2.2/usb_host/
The linked page had source for the kernel and drivers you'll need ... GOOD LUCK, you'll need it
Last year I worked on an application that had a PC component and a smartphone component, and the two were communicating over a USB connection (using ADB port forwarding and regular sockets). So, if you want to do something like that, I'll show you how I did it, maybe it's helpful.
USB On-The-Go (USB OTG or just OTG) is a specification first used in
late 2001 that allows USB devices, such as tablets or smartphones, to
act as a host
#Wikipedia, If anybody is still looking for it
In order to manage usb traffic your device needs to become a host according to USB specification.