【问题标题】:Android to Linux Bluetooth not finding all UUIDsAndroid 到 Linux 蓝牙未找到所有 UUID
【发布时间】:2018-05-21 21:49:51
【问题描述】:

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

但不显示我添加的自定义项,并且如果我尝试连接它会出错。如何连接到自定义配置文件/服务?

【问题讨论】:

  • 您在日志中看到的第三个 UUID 就是您添加的那个。它面临字节序问题并以相反的顺序显示 UUID。
  • @Ravi 啊,我一定错过了。您能否将此作为答案提交,我会将其标记为正确。

标签: android linux bluetooth dbus bluez


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 1970-01-01
    相关资源
    最近更新 更多