蓝牙GATT - onServicesDiscovered(GATT BluetoothGatt,诠释状态)不包含所有服务 [英] Bluetooth GATT - onServicesDiscovered(BluetoothGatt gatt, int status) does not contain all Services
问题描述
我有code连接到,然后试图发现由定制BLE服务器设备的广告定制服务提供的所有服务。
I have code that connects to, and then tries to discover all Services provided by a custom BLE server device advertising custom Services.
在code 工作在
- 的Nexus 5采用Android 5.1
- 三星SM-T320采用Android 4.4.2
- 中兴刀片VEC的4G的Android 4.4.2
code 不起作用在
- 三星SM-T360采用Android 4.4.4
- 三星GT-I9195采用Android 4.4.2
在设备的地方失败,往往发现所有的BLE服务在一(二)设备的通告相同BLE服务。重新启动Android设备和/或带有WiFi摆弄/ BT使得它发现其他BLE设备上的所有服务,但随后不是第一次(!)。
On devices where it fails it often discovers all of the BLE Services on one (of two) devices that advertises the same BLE Services. Restarting the Android device and/or fiddling with wifi/bt makes it discover all the Services on the other BLE device but then not the first (!).
与有关BLE服务发现三星的设备上优秀的bug任何人都知道?
Anyone knows of a outstanding bug with the Samsung devices regarding BLE Service discovery?
拥有所有的服务:
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
对于第二个(不及格)扫描我还可以看到以下日志:
For the second (failing) scan I also see the following logs:
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!
更新:
进一步的调查表明,onServicesDiscovered(GATT BluetoothGatt,诠释状态)返回所有BLE服务如果只有一个BLE服务设备是present一次。某种资源泄漏的较低层?
Further investigation shows that the onServicesDiscovered(BluetoothGatt gatt, int status) returns all the BLE Services if only one BLE service device is present at a time. Some kind of resource leak in the lower layers?
推荐答案
确定这样简单的答案是不要叫 connectGatt(上下文的背景下,布尔自动连接,BluetoothGattCallback回调)
其他任何线程,但主线程。
Ok so the short answer is do not call connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback)
on any other thread but the main thread.
如果我得到了一个 onLeScan(BluetoothDevice类设备,诠释RSSI,字节[] scanRecord)
在连接到设备I缓存的参考和后来被称为 connectGatt()
回调 onConnectionStateChange(GATT BluetoothGatt,诠释状态,INT newState)
从第一设备断开连接后里面。这导致了在这个问题上描述的问题。
If I got a onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)
while connecting to a device I cached the reference and later called connectGatt()
inside the callback onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
after a disconnect from the first device. This caused the issue described in this question.
这篇关于蓝牙GATT - onServicesDiscovered(GATT BluetoothGatt,诠释状态)不包含所有服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!