Live data transfer over USB - android

I'm trying to figure out how to transfer frames rendered on a computer to an android phone. Wifi and Bluetooth aren't fast enough for a smooth framerate, but the data transfer speed across the USB connector is more than enough (up to 480 megabytes/ second). Thing is, I can't figure out how to do it- there's nothing in the Android docs and I haven't found anything online. How can I access the USB connection?

You can't access the USB connection in any documented and supported fashion.

It's not possible at all? Are there any hacks that allow it?
It's not an app for publication, and I don't mind messing with my own phone.

Try turning debug mode on and using adb to connect to the device. You can manually push files to the phone (e.g. to the sdcard) which you can in turn periodically check in your app. You can also write files the other way around (from your app) and have your PC app check that file, again over ADB. That way you can establish simple protocols for communication.
I also need this right now, but a bit more difficult since I try to access the phone from an programmable integrated device with USB host chip inside. Which probably means reverse engineering ADB...
Either way, it's a pretty hacky solution but it should work over all phones as long as debug mode is turned on, which makes it feasible.

Related

Transfer large files between Android and Node.js

I have a photo-taking Android app (written in React Native, but I can add native modules if need be) that pairs with a gallery-type app on the user's computer (written in Electron with React). The number of photos can be large (we've had upwards of a thousand photos at a time), and they need to be transferred, uncompressed and uncropped, to the computer app. I need a reliable way to do this without routing the data through the Internet first.
Things I've tried
Node USB: Looks like a good library, but is unusable without installing a driver on the user's computer. The driver then appears to replace the default Windows USB driver, and the phone becomes inaccessible through normal means (opening a file explorer in Windows). Perhaps there's some way to switch drivers "on the fly", using the driver only while transferring photos, and then switching it back out for the system driver once we're done?
ADB: This is the original solution I tried, and it does exactly what I need it to, with two dealbreaking problems: for one, the phone needs to have Dev Mode enabled, and for two, ADB doesn't seem to recognize all devices (we've had a lot of trouble getting it to work with an LG V20, for example). The ideal answer to this question would be something like ADB without those two issues.
WiFi routing: we connect the phone to the same WiFi network as the host computer, use WebSockets to handshake IPs through the Internet, and then initiate a direct connection over the WiFi network. If I cannot find any other solutions, this will likely be the one I'll go for. The biggest problem with this option is the relatively large amount of manual setup required. Our users don't tend to be very technically savvy, and I don't know how reasonable it is to assume they will have WiFi in their home. At any rate, this cannot be the only option for transfer. Further, transferring gigabyte(s) of photos over the wireless network will cause a slowdown for everyone on the same network.
Tether routing: we tether the phone to the computer, and initiate a direct connection much in the same way as in the above step. The downsides to this method are that only phones with SIM cards can activate tethering (not all of our phones have SIM cards, as connectivity isn't their primary purpose for our needs), plus all of the other traffic on the computer will now be routed through the phone, which would be bad for customers' data caps who do have SIM cards. Additionally, there is no way to programmatically turn tethering on, there is only the ability to bring up the tethering menu; it's not too big a dealbreaker, but the other two very much are.
Bluetooth: Generally meets my requirements, but the data transfer rate is far too low, being an order of magnitude below WiFi.
WiFi Direct: I did not actually try this, because I could not find a working way to have the PC accept the WiFi Direct connection. It promises exceptional speeds, but there are no modules or libraries that I've found that would help me enable it.
SD Card: The lowest of the low tech methods, just save everything to the SD card and have the client take the card out and plug it into their computer. Would hands-down go with this, except for the need for a SD card port (guaranteed neither for the client's computer or their phone).
The obvious: manual drag and dropping required files from the phone to the PC. This is how we do things now, and it's fraught with problems. Text files have the last 15-20 characters cut off from them, for some reason, during transfer; many of the photos on the device do not initially show up due to the known issue with MTP not forcing a media rescan on the phone; and users sometimes drop files in the wrong places, leading to unnecessary support calls. This method surely needs to be replaced.
I've been searching for a solution for this problem for two months now, and it's hard to believe that nobody has had a use case for Android like this. It's been made clear that USB communication between Android and PC is non-trivial, I'm sure there are programs that do that, Windows to start off with. Yet try as I might, there are no solutions that work out of the box. Has anyone dealt with an issue like this before? What were your solutions? How would you approach this problem?
When downloading large files on Android it is recommended to use Download Manager, it supports a lot of native features like the progress bar, and notification, also the download task will be handled by OS, and more efficient.
React Native Fetch Blob library support this feature
You dont really need to route the data through the internet.
You can just exchange meta data through the internet:
Extend your desktop app with folder-import functionality (Plug your phone normally via USB, brose to the folder, import).
When you execute this process, let it notify a webservice of some sort (push notifications? Im no phone-app dev.) with which files the desktop-app has imported from which device (ids, filenames, ...) and the phone gets this meta data and can continue its process of whatever it is doing!
Obviously the best solution is a communication channel over USB. Until you figure that one out, you could implement it temporarily this way!

Streaming data from an Android device to a PC via USB

I need to stream a set of numbers, 6 floats, from an android device to a PC, to which it is connected by a USB cable. All the solutions I have found proposes using a WiFi connection. However, I have found that the latency caused by this is not acceptable. As such I have decided that I am going to hire someone to integrate the components, thus enabling direct communication. Until then, however, I want to try a variety of devices to see what works and the quickest way to "Integrate" two devices is by allowing them to share a (US)Buss. However, this is the one field I have zero experience with.
Do you make a socket and treat the connection as a network connection or is there another fancier way to achieve what I want? I have seen some talk about making a device driver for this purpose and I do not feel like crashing my OS 500 times again. I find it hard to believe that the android devices do not have some kind of driver already made that I can exploit.
The android code is written in Java, but it could be changed depending on what people suggest. The main chunk of mys system lies on the PC and is written in C++.
I need the latency of the stream to be as low as possible since the entire system needs to be as real time as possible. The limit is 15 ms between data acquisition on the device and the rendering of the simulation on the PC.
TL/DR: I need to stream data from a program on an android device to a PC with as little latency as possible; i.e. one way communication. As long as I can stream bytes I can design protocols and translate the bytes on the receiving end. My global cap is 15 ms and I need to stream continually updated 6 floats. What is the best way to achieve this?
Thank you in advance for your help.
Raw USB is probably not the way to go. USB is a device-oriented specification and cannot be used in a general send-arbitrary-bytes-across-a-wire way.
If Wi-Fi really is too slow, you could try purchasing an Android-compatible USB-Ethernet adaptor and connecting the device to the computer via a wired network connection, which might reduce the latency. Android recognises many types of these adaptors and you communicate over the network connection in the same way as other networks.
We ended up using the ADB brigde and it seems to be stable and fast enough for our purposes. All we had to do was to open a socket and connect with TCP. For some reason it fails when we try to connect with UDP, but I assume this might be due to ignorence on our part.

Simulate USB/Bluetooth HID device locally in order to inject events?

Is it possible to simulate a USB or Bluetooth device connected to Android?
I would like to make an app which is able to simulate an HID device locally. What I mean by this is: the app should make Android believe that an USB/Bluetooth HID device is connected. This would allow my app to inject touch events globally, I hope. Is there anyway to simulate a (virtual) device? Note that I don't really care about the device, I just want to use the built-in support for HID input.
I know a lot of people already asked about touch event injections but this approach seems to be a little bit different. I do not want to use this for testing purpose, so InstrumentationTestCase and the like won't help.
Rooting the device might be an option, although I can also imagine to ask my endusers to install a specifically signed app manually (according to https://stackoverflow.com/a/16737083/2923406 and https://stackoverflow.com/a/22902808/2923406 this works, but it would be device specific).
I am aware of:
Simulate a mouse input on android - This guy seems to do it in his own app, although his questions wasn't answered ;)
http://www.pocketmagic.net/2013/01/programmatically-injecting-events-on-android-part-2/#.U58SqfldVHV - Needs Root. Did anyone succeeded in using this? Also, the solution seems very device-specific again.
Bluetooth + simulating mouse - That's not what I want. The phone itself should not be an HID device, but use the (virtually created) one itself. Same for this:
https://stackoverflow.com/a/8174973/2923406
Note that I do not want to turn my phone into an HID device of any kind.
Simulating is a broad term. When I created my Bluetooth app I "simulated" a Bluetooth connection in two ways.
Way 1: Use a serial port UART converter and hook it up to a Bluetooth module transmitter.
Then you can use a terminal program like CoolTerm, to send your data.
Like so. In this case I coded in a string to send on successful connection with the device however you can make a infinite loop for testing purposes effectively not requiring your phone to be turned into a HID device.
Way 2 (not easy): Use your computers bluetooth in a server/client relashionship model.
This is harder to do. What you can do is convert your pc/mac into a server and the Android phone into a client or vice-versa. For this you will need to write external code which will need to be compiled separately on a jvm(java virtual machine). The procedure to do this can be found here. If you are using a Linux machine you have to separately download the Bluez module. I have not tried this on any other operating sytem other than Ubuntu, and it was a pain to get functional.
Hopefully that helped.
Yes, it's quite easy using the AOA2 protocol check this & this links for details ( you'll need to switch your device to the Accessory mode )
This may be possible (or at least be easier) using the Robolectric library, which simulates a full Android device locally. Although it is intended primarily for testing, the fact that it simulates a whole device locally - including Bluetooth and USB - means adding to it may be an easier approach.
In other words, you may be able to modify the classes it uses to simulate these abilities locally (i.e. in the IDE itself without an emulator or device) in order to simulate them on the device itself. After all, it does provide full simulations of these functions. You could simply change these Bluetooth and USB simulating classes to load onto the device itself rather than onto the local Robolectric test "device."
This is just an idea though - I can't confirm this will work - it just might be a good place for you to start.

low latency data link pc to android

can anyone recommend a method for low latency bi-directional com link between my pc app and android slave app. the app i have works now via wifi but the latency is too slow (about 300mS), i'm looking to get it down to 10mS or so.
the android is acting like a glorified remote control to the game on the pc. the apk displays a low res image and sends button presses back to the game and the round trip need to be quick
i'm thinking the only option beside the network, is to connect a usb cable but i don't see a lot of support for that path and not even sure it would be lower latency than wifi
any ideas please?
USB would have much lower latency, and there's plenty of USB support in Android. Check out http://developer.android.com/guide/topics/connectivity/usb/accessory.html Bluetooth may also be an option, but I'm not sure if it will get you to the latency you want- USB can.

Connecting android app with application on a pc

I am currently trying to write an android App that is connected to a application running on a pc (even though windows is preferred linux would be ok, too) via either USB or Bluetooth. Right now I'm not really sure how far this is possible. As far as I understand the USB Android API, I can not really use USB to talk to another application. Only raw file exchange seems to be possible. The Bluetooth idea seems a lot more feasible as I see it. I'd write a bluetooth server for the PC and connect to it via a Bluetooth client written via Android API. Point is, is that possible with windows? Has anyone seen any examples for what I am looking for? All I can find for USB is teethering which is not what I want.
There are android applications which allow you to use your mobile's touchscreen act like a touch pad which can be used to control your pc or laptop via bluetooth or wifi connection just like you are using your laptop's touch pad. PremoteDroid, RemoteDroid, Gmote etc.. to name a few (or only these are available i guess!).
But to do so you also need to develop a server application which will run on the device you wish to control and help u make connection between your mobile and the device. I have used PremoteDroid and RemoteDroid and they both work well on my laptop which runs windows 7. You can even add keyboard functionality.
PremoteDroid is openly available here: http://code.google.com/p/premotedroid/
I have a Bluetooth server application on my Mac that I use to test an Android app I'm writing. The app will eventually be used to communicate with a device with a microcontroller and bluetooth modem, but I needed a way to test the app in the absence of that device. The server app is written in Java, so I think it should work on a PC (and almost certainly in Linux).
I'm happy to share the code with you--I found it somewhere on the Internet (though I can't seem to figure out where now) and modified it as I needed to. It uses the BlueCove library, and is only about 60 lines, including several imports (and the code I commented out but didn't bother deleting :). I also have a Bluetooth client program on my Mac, since my app also has server functionality.
I have never tried to do anything like this using USB.

Categories

Resources