gpt4 book ai didi

android - 蓝牙 GATT - onServicesDiscovered(BluetoothGatt gatt, int status) 不包含所有服务

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:36:55 27 4
gpt4 key购买 nike

我有代码连接到广告自定义服务的自定义 BLE 服务器设备,然后尝试发现它提供的所有服务。

代码适用于

  • Android 5.1 的 Nexus 5
  • 三星 SM-T320 Android 4.4.2
  • ZTE Blade Vec 4G Android 4.4.2

代码不工作

  • 三星 SM-T360 Android 4.4.4
  • 三星 GT-I9195 Android 4.4.2

在出现故障的设备上,它通常会发现一个(两个)设备上的所有 BLE 服务,这些设备通告相同的 BLE 服务。重新启动 Android 设备和/或摆弄 wifi/bt 使其发现其他 BLE 设备上的所有服务,但不是第一个(!)。

有人知道三星设备关于 BLE 服务发现的一个突出错误吗?

拥有所有服务:

04-16 13:28:00.999: V/ScanningState(9741): onServicesDiscovered()
04-16 13:28:00.999: I/ScanningState(9741): The device has service 00001800-0000-1000-8000-00805f9b34fb
04-16 13:28:00.999: I/ScanningState(9741): The device has service 0000180a-0000-1000-8000-00805f9b34fb
04-16 13:28:00.999: I/ScanningState(9741): The device has service 0000180f-0000-1000-8000-00805f9b34fb
04-16 13:28:00.999: I/ScanningState(9741): The device has service f0ba0000-c6b5-11e2-8b8b-0800200c9a66
04-16 13:28:00.999: I/ScanningState(9741): The device has service f0ba0100-c6b5-11e2-8b8b-0800200c9a66
04-16 13:28:00.999: I/ScanningState(9741): The device has service f0ba1100-c6b5-11e2-8b8b-0800200c9a66

缺少服务:

04-16 14:05:31.179: V/ScanningState(10710): onServicesDiscovered()
04-16 14:05:31.179: I/ScanningState(10710): The device has service 00001800-0000-1000-8000-00805f9b34fb
04-16 14:05:31.179: I/ScanningState(10710): The device has service 0000180a-0000-1000-8000-00805f9b34fb
04-16 14:05:31.179: I/ScanningState(10710): The device has service 0000180f-0000-1000-8000-00805f9b34fb
04-16 14:05:31.179: I/ScanningState(10710): The device has service f0ba0000-c6b5-11e2-8b8b-0800200c9a66
04-16 14:05:31.179: W/ScanningState(10710): Device is missing sensor service
04-16 14:05:31.179: W/ScanningState(10710): Device is missing storage service
04-16 14:05:31.179: I/ScanningState(10710): Candidate did not support required services

对于第二次(失败的)扫描,我还看到了以下日志:

04-16 14:24:26.310: D/BtGatt.GattService(2856): onGetCharacteristic() - address=00:07:80:13:14:33, status=133, charUuid=00000000-0000-0000-0000-000000000000, prop=0
04-16 14:24:26.310: D/BtGatt.btif(2856): btif_gattc_get_included_service
04-16 14:24:26.310: D/BtGatt.btif(2856): btgattc_handle_event: Event 1011
04-16 14:24:26.310: E/bt-btif(2856): No server cache available
04-16 14:24:26.310: E/BtGatt.btif(2856): bta_to_btif_uuid: Unknown UUID length 25104!

更新:

进一步调查表明,如果一次只有一个 BLE 服务设备存在,onServicesDiscovered(BluetoothGatt gatt, int status) 会返回所有 BLE 服务。下层是否存在某种资源泄漏?

最佳答案

好的,简短的回答是不要在主线程以外的任何其他线程上调用 connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback)

如果我在连接到设备时得到了 onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord),我会缓存引用,然后在内部调用 connectGatt()与第一个设备断开连接后的回调 onConnectionStateChange(BluetoothGatt gatt, int status, int newState)。这导致了这个问题中描述的问题。

关于android - 蓝牙 GATT - onServicesDiscovered(BluetoothGatt gatt, int status) 不包含所有服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29674227/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com