2017-06-19 108 views
1

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

当我们关闭我们的应用程序时,设备断开连接。然后我们可以杀死我们的应用程序。大约20秒钟后,手机重新连接至设备约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) 

我感到莫名其妙;任何帮助表示赞赏!

+0

您可以显示您的代码和日志从应用程序? –

+0

在Android中看起来像是一个bug。 – Emil

+0

用日志编辑的帖子。代码太长并涉及到,但是在断开连接时,我们将所有订阅取消订阅到'Observable '。 –

回答

0

罪魁祸首是Spotify的连接。它监视任何断开的蓝牙设备并立即尝试连接到它。有时会进入无限循环,有时连接周期最终会停止。但是我们可以通过停止SC来摆脱这种破坏性行为,并且我们可以通过安装SC来使其发生在其他手机上。

另请参见Android BLE unexpectedly and repeatedly reconnects to peripheral

0

确保当您从您的应用与关贸总协定的个人资料,你有自动连接标志设置为false从Android的documentation的BLE: -

连接到GATT服务器与BLE 交互的第一步设备连接到它 - 更具体地说,连接到设备上的GATT 服务器。要连接到BLE设备上的GATT服务器,您使用connectGatt()方法 。此方法采用三个参数: 上下文对象,AUTOCONNECT(布尔值,指示是否 当它变得 可用立即自动连接到BLE设备),以及一个BluetoothGattCallback的引用:

mBluetoothGatt = device.connectGatt(this, false, mGattCallback);

+0

如果你正确调用断开连接()在BluetoothGatt对象然后它不起作用,无论你将autoConnect设置为true或false。 – Emil

+0

@Emil:我暗示了远程堆栈上的潜在错误 - 由OP应用程序中的自动连接引起 - 所以我想排除这种情况 – Zakir

+0

Autoconnect是错误的。如上所述,在RxAndroidBle中,您不直接调用disconnect();而是取消订阅注册该连接的Rx Observables。 –

0

确保你叫close方法。

close method

+0

我正在使用RxAndroidBle库;你实际上不调用'close()',你将取消订阅与该连接有关的所有Observable。实际上,我在日志中看到断开无线电操作,因此它似乎正确断开连接。 –

相关问题