【问题标题】:Invalid UUID/Services returned while scanning paired devices扫描配对设备时返回无效的 UUID/服务
【发布时间】:2022-07-15 02:28:03
【问题描述】:

我正在尝试根据已配对设备列表中的服务查找特定类型的设备,但是当我获得设备 UUID 时,设备支持的服务实际上都没有显示。

我不想device.connectGatt(this, false, gattCallback); 对每一个配对的设备最终找到正确的设备,因为它效率低下。

相关代码段如下

            for(BluetoothDevice device : bondedDevices) {
                ParcelUuid temp_uuids = device.getUuids();
                for (ParcelUuid uuids : myUuids) {
                    if (uuids.equals(temp_uuids)) {
                        targetDevice = device;
                        return targetDevice;
                    }
                }
            }
           Log.d(TAG, "Target Device Not Found");
           return targetDevice;

从未满足检查等于的if (uuids.equals(temp_uuids))statement,我相信我的蓝牙设备应该在其包含在SDP中的服务列表下添加GATT服务UUID,但由于某种原因它没有被检测到。

【问题讨论】:

    标签: java android bluetooth bluetooth-lowenergy uuid


    【解决方案1】:

    根据我的理解和解决我自己的问题: 问题:尚未启动 BLE 连接,因此我正在阅读蓝牙经典服务而不是 BLE。因此,阅读不正确的。 (不确定是否适用于所有 Android 版本或仅适用于 Android 10)

    为了解决这个问题,我重新开始检查蓝牙设备的地址。这是因为我的目标是只连接到某个品牌的设备,并且它们只有一组特定的供应商地址。然后我在建立连接后检查 UUID。

    希望这对将来遇到此问题的人有所帮助。

    【讨论】:

      【解决方案2】:

      听起来不可靠。 getBondedDevices 仅返回较早配对的设备。 getUuids 提供服务 UUID 的本地副本,前提是首先发现服务。

      startScanScanFilter 中的所需服务UUID 一起使用,以使附近的所有设备都满足过滤器。

      【讨论】:

      • 我之所以使用getBoundedDevices,是因为我只想先扫描已经配对的设备。如果设备已经配对,startScan 会不会不起作用?
      猜你喜欢
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多