Android Bluetooth无法保持与设备的连接

Android Bluetooth无法保持与设备的连接,android,bluetooth-lowenergy,android-bluetooth,android-ble,Android,Bluetooth Lowenergy,Android Bluetooth,Android Ble,我正在运行,无法保持设备连接。我觉得我有点随意的行为。蓝牙通常不会在第一次尝试时就无法连接(因此通常我几乎想说永远不会连接) 大约50%的时候,当我按下连接按钮时,应用程序会说状态已连接。然而,硬件设备有一个LED,当它连接时应该会亮起来,但不会亮起来。然后5或6秒后,它进入断开状态。我怀疑它正在连接一瞬间,然后断开连接,而应用程序只是在一段时间内没有收到备忘录。以下是日志: D/BluetoothGatt: connect() - device: 54:4A:16:2F:3C:F6, auto

我正在运行,无法保持设备连接。我觉得我有点随意的行为。蓝牙通常不会在第一次尝试时就无法连接(因此通常我几乎想说永远不会连接)

大约50%的时候,当我按下连接按钮时,应用程序会说状态已连接。然而,硬件设备有一个LED,当它连接时应该会亮起来,但不会亮起来。然后5或6秒后,它进入断开状态。我怀疑它正在连接一瞬间,然后断开连接,而应用程序只是在一段时间内没有收到备忘录。以下是日志:

D/BluetoothGatt: connect() - device: 54:4A:16:2F:3C:F6, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=60edb0ed-90de-4d7d-b4d0-690bcc359fb7
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=10
D/BluetoothLeService: Trying to create a new connection.
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=10 device=54:4A:16:2F:3C:F6
I/BluetoothLeService: Connected to GATT server.
D/BluetoothGatt: discoverServices() - device: 54:4A:16:2F:3C:F6
I/BluetoothLeService: Attempting to start service discovery:true
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=00001800-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=00001801-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=0000ffe0-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a00-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a01-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a02-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a03-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a04-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a05-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=0000ffe1-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002902-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002902-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002901-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onSearchComplete() = Device=54:4A:16:2F:3C:F6 Status=0
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=10 device=54:4A:16:2F:3C:F6
I/BluetoothLeService: Disconnected from GATT server.
可能有10%的时间我按了连接按钮,却没有看到任何事情发生:

D/BluetoothGatt: connect() - device: 54:4A:16:2F:3C:F6, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=7dbe26bc-4cee-48d2-9f47-59af4edb33bb
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
I/BluetoothLeService: Disconnected from GATT server.
D/BluetoothLeService: Trying to create a new connection.
而且可能有30%的时间它实际上是连接的

可能是硬件/固件问题。虽然我用iPhone连接设备时没有问题,但我想得出结论,android代码在某个地方坏了。我可以发布所有的BLE代码,但实际上我只是下载了示例,这样我就知道我没有弄坏任何东西

编辑:为那些关注我数学的人。最后10%的时间应用程序在扫描时找不到任何东西,我必须重新启动应用程序

编辑:我从play store下载并尝试了另外两个BLE应用程序,遇到了与google示例BLE应用程序相同的连接问题。android的BLE实现是否需要一些与iOS不同的设置?

尝试使用: connectGatt(上下文上下文、布尔自动连接、BluetoothGattCallback回调、int传输)

用运输工具作为运输工具


这对我来说很有帮助。

嗨,你找到这个问题的根本原因了吗?我面临着同样的问题,但却找不到同样的理由。我读过很多书,说android BLE sdk很糟糕,因为每个硬件制造商都使用不同的BLE芯片,所以很难有一个可靠的通用android BLE sdk。另一个问题是我们的芯片没有校准到正确的波特率。我猜软件时钟中有10%的差异导致我们丢弃数据包。(我认为这是正确的-我不是硬件专家)嗨@Chase,谢谢你提供详细信息。你是对的,这是由于校准问题。现在很少发生这种情况。谢谢你的帮助和支持