Android 到 Linux 蓝牙找不到所有 UUID

标签 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,并不是所有的都显示出来:

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。

关于Android 到 Linux 蓝牙找不到所有 UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47700977/

相关文章:

php - Fail2ban - 使用 exec 或 shell_exec 从 php 脚本手动添加 ip

python - 用于手机的远程蓝牙摄像头触发器

android - 设置新语言 : TextToSpeech. 之后,在返回新的 TextToSpeech(..) 实例之前调用 onInitListener

c# - 显示灰色的推送通知图标

linux - 无法从 USB 安装 openSUSE 13.2 - linuxrc 启动

新内核编译问题

android - 在 Android 2.3 上实现 OBEX 推送服务器

java - Android:蓝牙 - 如何读取传入数据

java - Objective-C 和 Android

android - 适配器在 Mvp 模式中的作用?