Android到Linux蓝牙找不到所有UUID

时间:2017-12-07 17:51:18

标签: android linux bluetooth dbus bluez

我试图通过蓝牙在Android设备和Linux设备之间进行通信。使用以下代码在DBUS上注册bluez配置文件后:

bus = dbus.SystemBus()
bluezObj = bus.get_object(BUS_NAME, "/org/bluez")

profilePath = "/test/profile"
profile = Profile(bus, profilePath)

profileManager = dbus.Interface(bluezObj, "org.bluez.ProfileManager1")
profileManager.RegisterProfile(profile, uuid, dbus.Dictionary({
    "name": "EntireData Hardware Interface",
    "Service": uuid,
    "Role": "server"
}, signature="sv"))

loop = GLib.MainLoop()
loop.run()

在此之后,我可以通过运行bluetoothctl并输入show来查看个人资料的uuid:

[bluetooth]# show
Controller B8:27:EB:6C:B7:E5
        Class: 0x000100
        Modalias: usb:v1D6Bp0246d052B
...
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Vendor specific           (94f39d29-7d6d-437d-973b-fba39e49d4ee)
        UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)

但是,尝试从Android设备查询UUID时,并不会显示所有这些UUID:

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
final Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
for(BluetoothDevice device : pairedDevices) {
    ParcelUuid[] uuids = device.getUuids();
    for(ParcelUuid uuid : uuids) {
        Log.d(TAG, "Found UUID: "+uuid);
    }
}

仅在日志中显示:

Found UUID: 0000110e-0000-1000-8000-00805f9b34fb
Found UUID: 00000000-0000-1000-8000-00805f9b34fb
Found UUID: eed4499e-a3fb-3b97-7d43-6d7d299df394

但是我没有显示我添加的自定义内容,如果我尝试连接它,则会显示错误。如何连接到自定义配置文件/服务?

1 个答案:

答案 0 :(得分:2)

您在日志中看到的第三个UUID是您添加的。它面临一个endian问题,并以相反的顺序显示UUID。