使用反射,你可以調用隱藏方法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