使用反射,你可以调用隐藏方法getUuids()
在BluetoothAdater
:
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
ParcelUuid[] uuids = (ParcelUuid[]) getUuidsMethod.invoke(adapter, null);
for (ParcelUuid uuid: uuids) {
Log.d(TAG, "UUID: " + uuid.getUuid().toString());
}
这是在Nexus S的结果:
UUID: 00001000-0000-1000-8000-00805f9b34fb
UUID: 00001001-0000-1000-8000-00805f9b34fb
UUID: 00001200-0000-1000-8000-00805f9b34fb
UUID: 0000110a-0000-1000-8000-00805f9b34fb
UUID: 0000110c-0000-1000-8000-00805f9b34fb
UUID: 00001112-0000-1000-8000-00805f9b34fb
UUID: 00001105-0000-1000-8000-00805f9b34fb
UUID: 0000111f-0000-1000-8000-00805f9b34fb
UUID: 0000112f-0000-1000-8000-00805f9b34fb
UUID: 00001116-0000-1000-8000-00805f9b34fb
,其中例如,0000111f-0000-1000-8000-00805f9b34fb
是HandsfreeAudioGatewayServiceClass
和00001105-0000-1000-8000-00805f9b34fb
用于OBEXObjectPushServiceClass
。此方法的实际可用性可能取决于设备和固件版本。
无论如何,你怎么知道UUID是你的蓝牙设备@Ron? – gumuruh