Reputation: 10569
I am trying to connect to a android device using bluetooth and the following code:
public ConnectThread(BluetoothDevice bluetoothDevice) {
this.bluetoothDevice = bluetoothDevice;
ParcelUuid[] uuids = this.bluetoothDevice.getUuids();
for(ParcelUuid parcelUuid : uuids) {
Log.v("BluetoothService", "UUID: " + parcelUuid.getUuid().toString());
}
BluetoothSocket tempBluetoothSocket = null;
try {
tempBluetoothSocket = this.bluetoothDevice.createRfcommSocketToServiceRecord(uuids[0].getUuid());
} catch (IOException e) {
Log.e(TAG, "Socket Type: " + "create() failed", e);
}
this.bluetoothSocket = tempBluetoothSocket;
}
The output for the UUID's is the following:
02-16 18:27:34.334: V/BluetoothService(2865): UUID: 0000110a-0000-1000-8000-00805f9b34fb
02-16 18:27:34.334: V/BluetoothService(2865): UUID: 00001105-0000-1000-8000-00805f9b34fb
02-16 18:27:34.334: V/BluetoothService(2865): UUID: 00001115-0000-1000-8000-00805f9b34fb
02-16 18:27:34.334: V/BluetoothService(2865): UUID: 00001116-0000-1000-8000-00805f9b34fb
02-16 18:27:34.334: V/BluetoothService(2865): UUID: 0000110e-0000-1000-8000-00805f9b34fb
02-16 18:27:34.334: V/BluetoothService(2865): UUID: 0000112f-0000-1000-8000-00805f9b34fb
02-16 18:27:34.334: V/BluetoothService(2865): UUID: 00001112-0000-1000-8000-00805f9b34fb
02-16 18:27:34.334: V/BluetoothService(2865): UUID: 0000111f-0000-1000-8000-00805f9b34fb
02-16 18:27:34.335: V/BluetoothService(2865): UUID: 00001132-0000-1000-8000-00805f9b34fb
So if i understand that correctly those are the UUID's supported by the device. But if thats true why am i not able to connect to the device using one of those UUID's in my case the UUID at index 0?
02-16 18:27:34.369: E/BluetoothService(2865): read failed, socket might closed or timeout, read ret: -1
02-16 18:27:34.369: E/BluetoothService(2865): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
02-16 18:27:34.369: E/BluetoothService(2865): at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:512)
02-16 18:27:34.369: E/BluetoothService(2865): at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:523)
02-16 18:27:34.369: E/BluetoothService(2865): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:315)
Upvotes: 1
Views: 868
Reputation: 55
I had the same problem when stopped application and not closed connection. Required UUID appears only after phone reboot. BluetoothDevice has cached UUIDs. Run bluetoothDevice.FetchUuidsWithSdp(); for refreshing list of UUIDS.
Upvotes: 1