Android - 获取此设备的蓝牙UUID

Ron*_*Ron 14 uuid android bluetooth android-bluetooth

我正在浏览Stack和互联网,以获得一个简单的解决方案来获取UUID我目前正在使用的设备.我偶然发现了这样的帖子,但他们似乎都没有帮助我.

该文档告诉我有关此 getUuids()功能的信息,但在浏览Android蓝牙文档时,我最终得到了一个BluetoothAdapter,但我需要BluetoothDevice执行此功能.

所以我需要知道以下内容:

1)功能是否真的返回设备UUID?因为这个名字叫复数(getUuid s)

2)如何获得此实例BluetoothDevice

谢谢!

小智 17

使用反射,你可以调用隐藏方法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());
}
Run Code Online (Sandbox Code Playgroud)

这是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
Run Code Online (Sandbox Code Playgroud)

其中,例如,0000111f-0000-1000-8000-00805f9b34fbHandsfreeAudioGatewayServiceClass00001105-0000-1000-8000-00805f9b34fbOBEXObjectPushServiceClass.此方法的实际可用性可能取决于设备和固件版本.

  • 好吧,到目前为止这很棒 - 谢谢:)但是我怎么能得到代表我手机的uuid?或者我是否需要所有这些来识别我的想法? (2认同)