I have such requirement in which i have to transfer file on computer system, lets consider windows PC.
What i want to do is i have one screen with specific details,i am writing that values in one text file, now if user clicks on button then that file must be copied to computer at specific location using USB.
I have tried to search about this but didn't get anything useful.I've also refer below link
http://developer.android.com/guide/topics/connectivity/usb/host.html
Is it possible in Android, how do i communicate with windows system ?
Regards
UPDATE :
I am able sopy files to Computer using adb
./adb -s emulator-5554 pull /sdcard/juned.jpg /root/juned/android_usb/
but can i do same thing from android application ?
I think your question is not very specific to be answered. But to explain a bit consider the following:
you have to turn your android device in USB host mode so that it enumerates connected USB devices
establish a connection to your receiving device. Probably this is going to be a storage or drive with a known configuration of endpoints
when established, use a function like bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout), which is documented as well in the link you provided. Keep in mind to choose the correct endpoint (direction TO your storage / drive)
This is just a sketch to get you started. It's clear that there is a lot more to do..
USB is probably not very suitable for what you want to do.
USB is asymmetrical, that is, a USB connection has a host at one end and a peripheral device at the other end. (For example, when you plug a USB stick into a PC, the PC is the host and the stick is the peripheral.) The host initiates and controls data transfers.
An Android phone generally acts as a peripheral device. As of Android 3.1, the phone can also act as a USB host, though not all phones support this.
In order to accomplish what you have in mind, the PC would need to run a piece of software that changes it from host mode to peripheral mode, and exposes some kind of storage that the Android device could then write to.
Maybe Bluetooth is a better option for you. You could just initiate a file transfer over Bluetooth as soon as the file changes. Inexpensive USB Bluetooth dongles are available for PCs without Bluetooth support. You might still need some software on your PC if you want to automatically accept the file transfer request on the PC.
Related
I am trying to make an android application that will stream live sensor data (e.g. accelerometer, etc) from my android device to my desktop computer.
My android device is connected to a WiFi network and my desktop computer is connected to a network with an Ethernet cable.
There are android applications available that send data from an android device to a PC via WiFi, but both devices must be connected to the same network.
Is there a way to transfer data if the two devices are connected to different networks?
Thank you!
Due to the fact that nearly every network sits behind a firewall (in most cases your home router/nat-device) you need to implement port-forwarding to access network 2 from network 1.
Another aproach would be to set up a VPN (f.i. with SSH) between the 2 hosts.
If your PC is directly connected to the internet, and has a public ip (that means, if you have NOT a RFC 1918 Adress), then you are able to directly connect to that ip by just entering that ip. If not, you need to implement something to get behind the firewall.
Simple answer; to stream data between a PC and an Android device each residing on different networks you need an intermediate server to pass the data through.
Now, if this just a small app that you are doing for your own purpose I suggest using the free version of Firebase (see https://www.firebase.com/). Their sample application that you'll find there, a simple chat service, does pretty much exactly what you need. Simply let the application on your PC (preferably a web app) read the "messages" that you send from your Android device.
I just started looking into OAPavailable in android.I came accros few doubts
Is accessory mandatory my android phone/table for me to talk to an external device over usb?Cant I talk to my external hardware using normal usb mode?Accessory mode means the phone will always be USB device and my external device will be the USB host.My application in phone should be able to talk to the external hardware regardless whether its a host or a USB device
What exactly are the difference between a USB host and device? Is it just that who powers the bus?When two devices connect how the device say "hey i will be the host and u be the device?"
In short my aim is I want to create an application that can talk to a usb device connected regardless its a usb device or a usb host.Can I acheive it using UsbManager apis without depending on OAP of Android
If you want to be able to work in either situation, you will basically have to write two communication subsystems, one using the APIs appropriate for each case.
It will be the external device and cabling which determines which mode is active (though if the phone cannot be a host, the connection of something external which requires that will be ignored, meaning no communication).
I'm working on a project to automate some tasks (such as play a song, play a video, receive bluetooth data, etc) on an Android phone from a PC.
Basically the PC will send a notifier to the phone and an app or something on the phone would then process the notifier and do 'something'. The opposite of this really:
http://code.google.com/p/android-notifier/
I've seen some examples showing how to send commands to an Android listener app or service via a network connection, but in this case, I would much rather the transmission be over a physical connection.
USB
Ideally, I'd like the connection to be via the USB port. But I've seen some posts online that suggest that the SDK does not natively support this. (Android apps, communicating with a device plugged in the USB port).
Is there some other SDK/API out there that makes this easier?
I've seen some posts on the ADB, but don't really get it... Would that work?
(http://developer.android.com/guide/developing/tools/adb.html)
Serial over USB
I've also seen some sites that show how to use a breakoutbox to perform bi-directional serial communication, but only with the G1. Is this possible with newer phones?
The Phone
I'm open to really any newish phone. I'm currently looking at the Galaxy S, because it has the video out through the headphone jack. I'm open to rooting if need be.
Implement a HTTP server in your app, then put your phone in USB Tether mode. This will create a local network between your phone and your PC. You should then be able to send HTTP request or create websockets using the phone's ip.
EDIT : I tested it, and it works, see here
What you can do is the phone acting as a server and then use adb to forward ports [1].
In this scenario the pc app would connect to localhost which would be redirected to the app on the phone via the usb cable.
But if you go this way, you might just as well simply connect directly to the phone's ip (without the adb port forwarding)...
[1] http://developer.android.com/guide/developing/tools/adb.html#forwardports
Is there a method to tether (USB wired) the GPS data from and Android phone to PC? I am using a GPSTether app currently that is based on the gpsd project.
I am loooking for alternatives that give more control and is less buggy than that app. Also, is there another method of doing this without using any third party apps?
I am working on a location aware software project and want to read the GPS data periodically. The GPSTether app does exactly that on a TCP port over telnet.
The ideal situation here would be to have a serial port over USB connection between your Android phone and your PC, and to stream NMEA across it from the phone. Unfortunately Android doesn't support USB in such a way natively.
GPSTether is a "hack" using the adb forwarding debug bridge in order to create the link between phone and PC, and then reads the NMEA from the location manager and sends it over the TCP/IP link created by adb forwarding.
If you are finding GPSTether too buggy, you really only have two choices either a) implement a version of GPSTether yourself, or b) come up with a different method for doing this. Both will involve quite a bit of coding.
For b), you might want to consider - writing NMEA to a file on the phone while it is connected to the PC as a USB Mass Storage device, and reading updates to the file from the PC regularly.
Or perhaps you could get a bluetooth dongle for your PC and "tether" the phone to the PC over bluetooth, by creating a bluetooth COM port connection for the GPS using something like the Android app BlueNMEA.
Or you could copy an FTP client program, and write the file to an FTP server on your PC over a WiFi connection (which would allow you to have the phone on the other side of the world from the PC).
This can be done using ShareGPS App available in Google Play Market and Franson GPSgate Client. You will have to redirect the android GPS NMEA signal to COM ports using these tools. In addition you will require to download AndroidSDK manager.
For detailed instruction see link below.:
http://sharedroid.jillybunch.com/user.html
Use Blue-NMEA http://max.kellermann.name/projects/blue-nmea/ on your android to send GPS NMEA data on bluetooth or on a local tcp server which can be accessed on PC by usb tethering or on WI-FI connection.
use VSPE (virtual serial port emulator) by eterlogic http://www.eterlogic.com/Products.VSPE.html (look for ur version of windows) and redirect data from tcp port to a com port of your choice and u r done with the settings. now configure 'google earth' ,'see you', 'GPSdata logger' or any other soft to listen to this com port which oftenly they will do by themselves.
http://max.kellermann.name/projects/blue-nmea/
sends nmea via bt com port or on a tcp port. make sure you read the readme to avoid common obstacles.
This is really late, but I have an old LG-P350 and on device manager it shows an NMEA interface. I don't really know how to use it though.
Is there anyway to read data from an attachment through the USB port on an Android device? In particular, an EKG. Most the work can be done by the hardware of the device to simplify the output to a single number, a voltage reading. If its not possible, what about modifying an accessory that can already communicate with an android device? Thinking of devices that attach to android phones, what about sending the data as an audio signal to be read as the microphone from a headset and then analyzing the audio signal to convert it to a number that can be used to display a value.
Any ideas on how to make this work?
The Android handset can't be used as a "USB Host" (it's in the google android wishlist as a bug/enhancement request). That's what you'd need to connect regular USB devices like your EKG monitor and memory card readers, etc. to it. I wish it could do this too and star'd that enhancement to vote for it...
I'm not sure if this will work for you, but here's something I did recently for a project where I needed a smartphone to communicate with a host PC.
I used ADB on the PC to do port forwarding and then I used sockets to do the communication. Server socket on the phone, client on the PC. I can give you more details if you want.
Of course, the clear requirement here is to be able to install and execute code on the "device" which I don't think is applicable to your problem. Other than that, I found no other way to communicate over a USB connection through Android.