bluebl1
bluebl1

Reputation: 176

How should I connect my Android Device to my laptop(for my app)?

I've seen a few people ask this in a couple of different ways, but the answer was always too complex or not detailed enough.

I want to take a survey of a lot of people at a robotics competition. I ask them questions, and mark the answers on my android-based device in check boxes, radio buttons, pull-down menus, etc. In fact, I will have multiple people working with me and asking people the same questions as me. I'll have one person at a laptop staying at his table. Whenever someone gets a few people to fill out the form, they need to put the data on the laptop. There lies the problem.

We won't have WiFi in this location. We probably will have Bluetooth, I'm not sure, but it seems like using a USB connection will be the easiest method(correct me if I'm wrong). I have a "Sync" button. When they press "Sync", the android device should send all of its new data to the laptop, and the laptop should send all of its new data(from the OTHER people surveying) to the android device. I'm using java on both devices. How do I do such communication?

That is what I want, but if I need to make it easier, I'd be willing to cripple the program to this: You can only store one form at a time, and the "sync" button will simply send that 1 form from the android device to the laptop, and the laptop won't send any data back. That'd be fine because they really should send the file to the laptop after every form, and they don't really need the forms.

Edit: if Bluetooth is easier, please say why. My guess (if it is easier) is because each Android device might have a different port to connect to the laptop, but I think Bluetooth is harder because I'm not sure how to pair the device to the laptop.

Upvotes: 1

Views: 5704

Answers (1)

Radu
Radu

Reputation: 2074

What you should do:

  1. Every phone used to survey should already be paired to your laptop. You should know how to do this.
  2. Have your forms, etc, do your Android app without the communication part first, and be sure to store your forms locally correctly.
  3. For transfer you just open BluetoothSockets on both PC and Android. Have a look at the BluetoothChat example. It's pretty simple. Remember that, since the Android starts the connection it should be Client, while the PC is a Server. Here is the Android documentation page.
  4. For logical sync of both PC and smartphone, you should have some sort of protocol. For example at first they both say what form numbers they have (PC might have forms number 1-19, 21, 23) (Android might have form numbers 20-23). Then they will exchange exclusive information only.

Don't forget to vote up if it's useful information.

Upvotes: 1

Related Questions