0

I have an android project that gets acceleration values using the accelerometer.

public void onSensorChanged(SensorEvent event){
float x,y; 
x = event.values[0];
y = event.values[1];
}

I also have a regular java project that draws a point at a given location (x,y) using java swing.

I want that location to be some manipulation of the x, y acceleration values I get from the android project. Like, onSensorChanged should call a method in the regular java project that draws the dot and pass the x, y values. So ultimately, the swing code will track the movement of the phone. But that's not the important part. I just want to know how I would connect an android project to a regular project that uses swing. Probably didn't express my intention well, but if anybody gets what I'm trying to do, please help.

1 Answer 1

1

To connect your Android Application with another Application that's running on a PC, you need a Socket connection between these 2 devices. One (maybe the Android Phone) should open a Port, and the PC then connects to the Phones IP:Port. Your Phone should listen to these connections and should write x,y to the connection. The PC can read it and can draw it in a Graphic.

For the Server you need the Java class SocketServer and for the Client the class Socket.

You can find some examples here: http://www.cs.uic.edu/~troy/spring05/cs450/sockets/socket.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. I will try to do that in the future. But for now, is it possible to do it while the phone is connected to the computer by the USB cable?
This is much more complicated. Use Sockets over TCP and you're on the right way ;-) On the Server: Create a SocketServer, accept incomming connections, create a PrintWriter for the socket outputstream and write the data you want to transmit. On the Client: Create a Socket to the server and read data if available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.