Question

I'm trying to create a server on android that will listen on incoming connections ,such as a specific headset i have.

I've read many tutorials, posts in StackOverflow and the one from Android|Developer , and i don't seem to understand a few things .

1) UUID , is it a specific address for each Bluetooth device ? or is it a shared key that need to be in the server and the client in order to create a connection ? my guess is the latter cause there the MAC address as well ...

2) When i pair my Headset with my phone , does the headset saves the MAC\UUID of the last paired device ?

3) Does the Bluetooth chips even works in that way ? The phone connects immediately to a paired device as it turned on, So my guess is that it opens a Socket for each paired device and waits for it to turn on , is that true ?

4) Is it possible to accomplish what im trying ? Meaning creating a BluetoothServerSocket that will accept a connection from the head set ?

code example for the server side:

//This may b needs to be the UUID of the headset ? or special one ? or what ?
UUID myUUID = UUID.fromString("0000111e-0000-1000-8000-00805f9b34fb"); 
private final BluetoothServerSocket mServerSocket;
private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(Activity.APP_NAME, myUUID);
mServerScooket = tmp;
//Im hoping that this will block until the specific headset will be turned on 
socket = mServerSocket.accept();

Thanks in advance.

Was it helpful?

Solution 2

1) yes UUID is specific to each device and in order to connect to a device you need to have its UUID. as shown in the Bluetooth chat example by Android SDK

2) depends on the hardware for example chip sets like the HC-06 does saves the last paired device UUID while the HC-05 dose not ...

3) The headsets that Ive tested (Samsung made) Acts as a server. so by initiating a BluetoothSocket with the UUID of the headphone u can connect to it.

4) Yes it is possible to connect to a Bluetooth head set answered in the post : Using the Android RecognizerIntent with a bluetooth headset

Special notes :

Best way to listen to oncoming connections without any wakelocks that I found is by registering the BluetoothDevice.ACTION_ACL_CONNECTED Broadcast and check the name\mac\UUID of each incomming connection.

Thanks to Hoan Nagayu for the help.

OTHER TIPS

1) UUID ,is a specific ID for Bluetooth communication. When you create your bluetooth socket in Android, listenUsingRfcommWithServiceRecord(Activity.APP_NAME, myUUID); ask Android to redirect bluetooth connection which match with the UUID to your app.

2) I'm not sure. It depends on the type of connection the headset can make. When you want to use it, do you need to select it in Android, or you can just put it and it works ?

3) I don't know. But you can have a look to Android source code ;)

4) If the bluetooth headset can create a connect socket, yes, it is possible

Hope this helps ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top