我正在尝试从已配对或未配对的远程设备中检索(服务)UUID。远程和本地设备都运行相同的程序,并且可以成功建立用于传输数据的套接字。但是,在两个设备上仅提取默认的预先存在的UUID。 我能够通过fetchUuidsWithSdp()查看特定于应用程序的UUID,但只能查看数十个UUID列表中的一次或两次。
所以我的问题是。为什么我的自定义/应用专用UUID未显示在通过bluetoothDevice.getUuids()显示的UUID列表中?当它确实出现(非常罕见)时,我无法复制这种行为?
if(intent.getAction().equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
Log.i(CLASS_TAG, "Discovery finished.");
for (BluetoothDevice device : pairedDevices) {
device.fetchUuidsWithSdp();
}
}
...
if(BluetoothDevice.ACTION_UUID.equals(intent.getAction())) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
for (ParcelUuid uuid : device.getUuids()) {
Log.i(CLASS_TAG, "action uuid: "+uuid);
}
}
日志输出:
11-28 15:55:03.910 15893-15893 / com.KoMark.Koala I / KComm:action uuid: 0000110a-0000-1000-8000-00805f9b34fb
11-28 15:55:03.910 15893-15893 / com.KoMark.Koala I / KComm:action uuid: 00001105-0000-1000-8000-00805f9b34fb
11-28 15:55:03.910 15893-15893 / com.KoMark.Koala I / KComm:action uuid: 00001116-0000-1000-8000-00805f9b34fb
11-28 15:55:03.910 15893-15893 / com.KoMark.Koala I / KComm:action uuid: 0000112f-0000-1000-8000-00805f9b34fb
11-28 15:55:03.910 15893-15893 / com.KoMark.Koala I / KComm:action uuid: 00001112-0000-1000-8000-00805f9b34fb
11-28 15:55:03.910 15893-15893 / com.KoMark.Koala I / KComm:action uuid: 0000111f-0000-1000-8000-00805f9b34fb
11-28 15:55:03.910 15893-15893 / com.KoMark.Koala I / KComm:action uuid: 00001132-0000-1000-8000-00805f9b34fb
客户端成功创建连接:
public ClientThread(BluetoothDevice device ) {
BluetoothSocket tmp = null;
mmDevice = device;
try {
tmp = mmDevice.createRfcommSocketToServiceRecord(UUID.fromString(KOALA_UUID));
} catch (IOException e) {
e.printStackTrace();
}
mmSocket = tmp;
}
UUID是:
private static final String KOALA_UUID = "e519c52c-81fb-11e5-8bcf-feff819cdc9f";