I've been sitting on this problem for a few weeks, sometimes it just randomly works, but I really need to understand how to get this to work on different devices.
I want to connect a android (phone) app with another one (google glass), through bluetooth. So I am calling "listenUsingRfcommWithServiceRecord" on my Glass Device. As far as I understand this SHOULD add the specified UUID to the SPD service of my Glass. I don't understand what the String name parameter does, to be honest so I just put my app-name. This is the code is use on Glass:
public BtServer() {
btAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothServerSocket tmp = null;
try {
tmp = btAdapter.listenUsingRfcommWithServiceRecord("phone", MY_UUID);
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
btServerSocket = tmp;
}
When I get the UUIDs of my Glass device on my phone and display them the UUID only shows on one of the Devices for some reason. This is the Code i use + output:
/**
* get paired glass devices
* @return set of paired glasses
*/
private Set < BluetoothDevice > getPairedGlass() {
final Set < BluetoothDevice > pairedDevices = btSocket.getPairedDevices(); //returns all bonded Devices
for (final BluetoothDevice e: pairedDevices)
if (e.fetchUuidsWithSdp()) {
final ParcelUuid[] uuids = e.getUuids();
for (final ParcelUuid b: uuids)
System.out.println("" + e.getName() + ": " + b.getUuid().toString());
}
return pairedDevices;
}
Output:
03-17 14:54:29.812: I/System.out(17149): xxx's Glass: 0000111e-0000-1000-8000-00805f9b34fb
03-17 14:54:29.812: I/System.out(17149): xxx's Glass: 00001115-0000-1000-8000-00805f9b34fb
03-17 14:54:29.812: I/System.out(17149): xxx's Glass: 00001133-0000-1000-8000-00805f9b34fb
03-17 14:54:29.822: I/System.out(17149): xxx's Glass: f96647cf-7f25-4277-843d-f407b4192f8b
03-17 14:54:29.822: I/System.out(17149): xxx's Glass: f15cc914-e4bc-45ce-9930-cb7695385850
03-17 14:54:29.822: I/System.out(17149): xxx's Glass: ab390c1b-9a5b-4104-932d-cce5e542b5c6
03-17 14:54:29.822: I/System.out(17149): xxx's Glass: ab390c1b-9a5b-4104-932d-cce5e542b5c6
03-17 14:54:29.822: I/System.out(17149): xxx's Glass: 5e8945b0-9525-11e3-a5e2-0800200c9a66
03-17 14:54:29.832: I/System.out(17149): Test Account's Glas: 0000111e-0000-1000-8000-00805f9b34fb
03-17 14:54:29.832: I/System.out(17149): Test Account's Glas: 00001115-0000-1000-8000-00805f9b34fb
03-17 14:54:29.832: I/System.out(17149): Test Account's Glas: 00001133-0000-1000-8000-00805f9b34fb
03-17 14:54:29.832: I/System.out(17149): Test Account's Glas: f96647cf-7f25-4277-843d-f407b4192f8b
03-17 14:54:29.832: I/System.out(17149): Test Account's Glas: 5e8945b0-9525-11e3-a5e2-0800200c9a66
03-17 14:54:29.832: I/System.out(17149): Test Account's Glas: f15cc914-e4bc-45ce-9930-cb7695385850
The UUID specified in both applications is "ab390c1b-9a5b-4104-932d-cce5e542b5c6".
This works just fine on my xxx Glass, but I can't get it to work on my Test Account Glass. I dont understand why fetchUuidsWithSdp for my xxx Device, as it isnt connected with my phone right now, returns true. So these outsputs are probably just local copies.
When calling "createInsecureRfcommSocketToServiceRecord(UUID)" on the phone i'm getting an IOException, because the there is no service with that uuid on my glass. When trying a different UUID, it also doesnt work.
So how do I set the UUID for my app on my Device? Or am i retrieving the UUIDs wrong and its actually set? I'd be so thankful, if someone knew how to do this.