我如何获得蓝牙设备的UUID?

Tom*_*ola 5 uuid android bluetooth

我需要知道API 8(2.2)或2.3.3上的UUID.

据我了解文档,应该允许:

    phoneDevice = blueAdapter.getRemoteDevice(phoneAddress);
    ParcelUuid[] phoneUuids = phoneDevice.getUuids();  // Won't compile
Run Code Online (Sandbox Code Playgroud)

Eclipse给了我: "方法getUuids()未定义为BluetoothDevice类型." 但请参阅:http: //developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids()

另外,我想知道UUID是如何在ParcelUuid []中"分配"的.如果我设法到达那里,如何从parcelUuid []中检索UUID?在我看来,Android蓝牙的文档似乎很差.

真是笑话!现在我尝试从意图中得到它,但这也给出了:*"EXTRA_UUID无法解析或不是字段"*:

intent.getParcelableExtra(BluetoothDevice.EXTRA_UUID); 
Run Code Online (Sandbox Code Playgroud)

Nak*_*aka 5

你必须使用反射在android版本<3上使用getUuids()和fetchUuidsWithSdp().所以,试试代码:

Method method = phoneDevice.getClass().getMethod("getUuids", null);
ParcelUuid[] phoneUuids = (ParcelUuid[]) method.invoke(phoneDevice, null);
Run Code Online (Sandbox Code Playgroud)


Pad*_*mar 2

//这将支持 API 级别 15 及以上。

Broadcast Action: This intent is used to broadcast the UUID wrapped as a ParcelUuid of the remote device after it has been fetched. This intent is sent only when the UUIDs of the remote device are requested to be fetched using Service Discovery Protocol
    Always contains the extra field EXTRA_DEVICE
    Always contains the extra field EXTRA_UUID
    Requires BLUETOOTH to receive.
    Constant Value: "android.bluetooth.device.action.UUID"
Run Code Online (Sandbox Code Playgroud)

//无法降低其相关硬件的性能。也没有支持罐子。http://developer.android.com/sdk/compatibility-library.html