Android 到 Linux 蓝牙未找到所有 UUID

Android to Linux Bluetooth not finding all UUIDs

我正在尝试通过蓝牙在 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

但不显示我添加的自定义项,如果我尝试连接它会出错。如何连接到自定义 profile/service?

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