Android BLE 在断开连接后在后台连接

标签 android bluetooth-lowenergy rxandroidble

我们使用 RxAndroidBle 1.3.1 从 Android 连接到 BLE 设备。在某些手机上(目前我在 LG V20 [LG-H918]、Android 7.0 上看到了这一点),在我们的应用程序断开连接后,手机将继续连接,无需任何用户输入。

当我们关闭应用程序时,设备会断开连接。然后我们可以终止我们的应用程序进程。大约二十秒后,手机重新连接到设备约 2 秒,然后断开连接。此行为每 10-20 秒无限期地重复一次,直到我们重新启动手机。

实际上,如果我们在连接仍然存在的情况下硬终止应用程序,我们甚至可以获得重复连接。

这些是我们断开连接时的日志:

06-21 10:51:07.464 26640-26640/com.hatchbaby.rest.qa I/Nightlight: [main] Disconnecting: Nightlight.disconnect()
06-21 10:51:07.528 26640-26640/com.hatchbaby.rest.qa D/BluetoothGatt: setCharacteristicNotification() - uuid: 02240003-5efd-47eb-9c1a-de53f7a2b232 enable: false
06-21 10:51:07.538 26640-26640/com.hatchbaby.rest.qa D/RxBle#Radio:   QUEUED RxBleRadioOperationDescriptorWrite(131621266)
06-21 10:51:07.539 26640-26690/com.hatchbaby.rest.qa D/RxBle#Radio:  STARTED RxBleRadioOperationDescriptorWrite(131621266)
06-21 10:51:07.543 26640-26640/com.hatchbaby.rest.qa D/BluetoothGatt: setCharacteristicNotification() - uuid: 02260002-5efd-47eb-9c1a-de53f7a2b232 enable: false
06-21 10:51:07.547 26640-26640/com.hatchbaby.rest.qa D/RxBle#Radio:   QUEUED RxBleRadioOperationDescriptorWrite(250764313)
06-21 10:51:07.548 26640-26640/com.hatchbaby.rest.qa D/RxBle#Radio:   QUEUED RxBleRadioOperationDisconnect(160892126)
06-21 10:51:07.562 26640-26640/com.hatchbaby.rest.qa I/Nightlight: [main] Nightlight state: RxBleConnectionState{DISCONNECTED}
06-21 10:51:07.686 26640-26747/com.hatchbaby.rest.qa D/RxBle#BluetoothGatt: onDescriptorWrite descriptor=00002902-0000-1000-8000-00805f9b34fb status=0
06-21 10:51:07.688 26640-26690/com.hatchbaby.rest.qa D/RxBle#Radio: FINISHED RxBleRadioOperationDescriptorWrite(131621266)
06-21 10:51:07.689 26640-26690/com.hatchbaby.rest.qa D/RxBle#Radio:  STARTED RxBleRadioOperationDescriptorWrite(250764313)
06-21 10:51:07.783 26640-26746/com.hatchbaby.rest.qa D/RxBle#BluetoothGatt: onDescriptorWrite descriptor=00002902-0000-1000-8000-00805f9b34fb status=0
06-21 10:51:07.786 26640-26690/com.hatchbaby.rest.qa D/RxBle#Radio: FINISHED RxBleRadioOperationDescriptorWrite(250764313)
06-21 10:51:07.787 26640-26690/com.hatchbaby.rest.qa D/RxBle#Radio:  STARTED RxBleRadioOperationDisconnect(160892126)
06-21 10:51:07.787 26640-26640/com.hatchbaby.rest.qa D/BluetoothManager: getConnectionState()
06-21 10:51:07.787 26640-26640/com.hatchbaby.rest.qa D/BluetoothManager: getConnectedDevices
06-21 10:51:07.793 26640-26640/com.hatchbaby.rest.qa D/BluetoothGatt: cancelOpen() - device: E5:D6:FC:68:FB:55
06-21 10:51:07.797 26640-26653/com.hatchbaby.rest.qa D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=E5:D6:FC:68:FB:55
06-21 10:51:07.797 26640-26653/com.hatchbaby.rest.qa D/RxBle#BluetoothGatt: onConnectionStateChange newState=0 status=0
06-21 10:51:07.803 26640-26640/com.hatchbaby.rest.qa D/BluetoothGatt: close()
06-21 10:51:07.803 26640-26640/com.hatchbaby.rest.qa D/BluetoothGatt: unregisterApp() - mClientIf=6
06-21 10:51:07.807 26640-26690/com.hatchbaby.rest.qa D/RxBle#Radio: FINISHED RxBleRadioOperationDisconnect(160892126)

我很困惑;感谢任何帮助!

最佳答案

确保您调用了close方法。

close method

关于Android BLE 在断开连接后在后台连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44640917/

相关文章:

swift - iOS 10.0 : Use of undeclared type 'CBCharacteristic'

android - 如何使用 RxAndroidBle 结合服务发现和读取特征

android - BxAndroidBle 无法读取设备,status=22

android - 将 timeout() 与 retryWhen() 结合使用

java - 从类构造函数创建一个按钮

android - 是否可以创建没有边框的 Android AlertDialog?

android - 如果在 Android 中连接 BLE 设备失败,如何通知用户?

linux - QT 低能耗 Controller 外设模式崩溃并出现错误 "Resource not available"

android - Dagger2 禁用 AndroidInjection.inject(this);用于仪器测试

android - 理想的Android Studio gitignore 文件