使用反射,您可以调用隐藏的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
是 forHandsfreeAudioGatewayServiceClass
和00001105-0000-1000-8000-00805f9b34fb
是 for OBEXObjectPushServiceClass
。此方法的实际可用性可能取决于设备和固件版本。