Jokovic12
Jokovic12

Reputation: 51

Connect Android to another device on bluetooth and send data

I want to create a connection between my Android and a PC (or another device) just like in the Bluetooth menu from settings. I have manage to get the list of all bt devices in my range and get their MAC addresses. So, I have the BluetoothDevice, how can i connect to it or pair with it? I saw a lot of stuff about creating a server on PC, but I don't want that, i just wanna connect with the device. My attempt were to get the UUID of the device and use createRfcommSocketToServiceRecord...but when i try socket.connect() it cannot connect (because I don't have a server). So practically I need to make the same structure that the OS is doing (connect with the device, if the connected device is trying to send i can receive the info and so on).

If I managed to connect with the device, I want to listen all that it is emitting, no matter the data...I haven't researched this topic, but any advice will be nice.

The connection must be made with any device that supports bluetooth, and I don't have access to it (of course the device is giving me the permission to connect).

Upvotes: 1

Views: 2424

Answers (1)

Andrew G
Andrew G

Reputation: 1557

Grab the Android sample projects by doing this http://developer.android.com/tools/samples/index.html

They have an app called BluetoothChat that pretty much does just what you want.

The thing about the 'server' is just in the connection, one side needs to open a listening port and that side is arbitrarily the 'server'. Once they are connected they are merely peers and you can write/read data till the cows come home.

Upvotes: 1

Related Questions