I'm trying to send data from android to a computer via USB,
I found the USB Accessory introduction, http://developer.android.com/guide/topics/connectivity/usb/accessory.html (Basically I want to send a few bytes to a programm on the computer) So, am i right on using the accessory on android? What would i use for the pc programm, and can I/ Do i have to create a socket connection from my application to the programm
You will need access to the USB device plugged in to the PC which lets you send USB Control Request and Bulk Transfer requests.
If you are using linux, you could try libusb - which is pretty straight forward to use. For windows am not sure though.
Related
I have a question about the p2p functionality of Android OS (4.x and higher). I have a PC program that makes use of the Boost C++ library that can function as a server or as a client. Now i have a Android app that has a server using Java sockets. This program need a accesspoint to connect to each other.
I'm looking for a way to connect the Android server and the PC client program without a accesspoint. After looking around i found out that Android has a p2p library.
Android P2P
As a read it you can only connect two Android devices with each other, my question is if it is possible to use this library to connect the Android device to the PC using wifi p2p? Or if there is a other possiblity? All suggestions are welcome!
Roy, have a look at this: http://en.wikipedia.org/wiki/Wi-Fi_Direct
WiFi P2P is now called WiFi Direct, and it is indeed possible to connect two devices as long as one of the devices supports it. So Android device in P2P mode and a PC without any special configuraiton should work fine. However, the PC can (probably) only connect to one access point at a time, from its perspective the Android device is the access point, it would have to disconnect from its usual access point to connect to the Android device.
Also check out SoftAP.
I want to do a simple project where I send the phone's gyroscope data to a computer, where both are connected over Bluetooth. The receiving computer will be using C++, which I assume has its own Bluetooth communication protocols.
I have no idea how to get started - does anyone have sample code or tutorials for this? Preferably for both the client (phone) and the server (computer).
I think you should use the SPP BT profile to continuously sending data over bluetooth.
You can see a SPP link over BT as an normal RS232 serial cable.
Here are a sample code how to create an app (bluetooth chat) in android using the spp profile.
http://developer.android.com/guide/topics/connectivity/bluetooth.html
On the computer side, are you using windows?
If so, the bluetooth stack on computer will create an COM port for you with the SPP data from phone.
I haven't create any application that read and write from a COM port in windows but I guess it will be tutorials on the net.
First step could be to connect an Hyper terminal to that COM port and see that you can read data from it.
I'd like to intercept SMS messages from an Android phone connected to PC over USB. Java app on PC side.
Where should I start? Would it be apps on both sides? Or is there some PC-side lib for that?
I've only found tips for serial port access like SmsJ.
Background :
When you attach phone with USB cable, your computer creates a virtual COMM Port and a new port number is assign to it. You can see the port number detail in Device Manager List.
Development Part:
For the starting you can read the Java's Port reading example. Just study this example and you will be able to connect and send SMS from your android phone. It will allow to fire you command in Computer that will actually goes to attached Phone. For sending command to COMM Port you will be requiring AT Commands to Send SMS. Using AT Commands, you will also be able to read SMS and perform other functions on the phone.
You can also connect your phone through bluetooth, It will also assign same virtual COMM Port and you can do all functionality as well.
I'm now writing a project on android and my program must able to transfer / replace a file to my computer with certain address to sync my app with my app on my computer and reverse (from PC to device) only by pressing a single button in my program.
Use http://developer.android.com/tools/help/adb.html#forwardports to forward a TCP/IP connection over the USB cable. Your app on the phone can act as a TCP server and receive arbitrary commands.
The downside of this solution is that you have to bundle the adb executable with your program and the user must have the proper drivers installed (that means mass-storage connection is not enough). The sources for adb are available, if you want.
I have an android devic, i wish to know when it is connected to the pc via java/.net
i know its possible - the Samsung New PC Studio is doing it, when ever i connect an android device it lets me know. how can i achieve the same?
You have to listen for one of this notifications
http://developer.android.com/reference/android/content/Intent.html
If you're using it as a mass storage device then use this
http://developer.android.com/reference/android/content/Intent.html#ACTION_UMS_CONNECTED
Other USB events aren't clearly described in the documentation
EDIT:
If you want to read on the computer side I would read this article
http://today.java.net/article/2006/07/05/java-and-usb
and then check which kind of devices are connected to the usb port. if it is a mobile phone, then you can try to send a short message to it. on your phone you make a small piece of code which returns an appropriate answer so you can detect thats its really android/your phone/this phones you want to identify
java device detection
This site have a guide on how to detect device with java web and java core
http://51degrees.com/Support/Documentation/Java/GettingStarted.aspx