设备断开连接后收到 android.bluetooth.device.action.ACL_CONNECTED

Posted

技术标签:

【中文标题】设备断开连接后收到 android.bluetooth.device.action.ACL_CONNECTED【英文标题】:android.bluetooth.device.action.ACL_CONNECTED received after device disconnected 【发布时间】:2017-11-14 06:56:04 【问题描述】:

我正在研究低功耗蓝牙设备(体重秤)。

我观察到了一些事情。当我尝试与 BLE 设备断开连接时,它会断开连接。我还通过调用以下行来删除债券。

method = mBluetoothGatt.getDevice().getClass().getMethod("removeBond", (Class[]) null);
method.invoke(mBluetoothGatt.getDevice(), (Object[]) null);

但是几秒钟后它突然显示为它与我的移动设备连接。当我关闭移动设备的蓝牙时,它(刻度)仍然显示连接符号。只有当我将移动设备更改为飞行模式时,它才会断开连接。

我在 android Monitor 中看到了以下日志。

11-14 10:55:23.438 15152-15207/? W/bt_btif: bta_dm_bl_change_cback : reason=0
11-14 10:55:23.438 15152-15207/? W/bt_btm: btm_acl_update_busy_level :: evt.busy_level_flags : 0x0
11-14 10:55:23.438 15152-15207/? W/bt_btif: bta_dm_bl_change_cback : reason=0
11-14 10:55:23.439 15152-15207/? W/bt_smp: smp_br_connect_callback is called on unexpected transport 2
11-14 10:55:23.439 15152-15207/? W/bt_btif: bta_dm_acl_change info: 0x0
11-14 10:55:23.439 15152-15178/? W/bt_btif: btif_dm_upstreams_cback  ev: BTA_DM_LINK_UP_EVT
11-14 10:55:23.439 15152-15178/? W/bt_btif: BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED
11-14 10:55:23.443 18042-18042/com.beurer.connect.healthmanager 11-14 10:55:23.449 15152-15178/? D/BluetoothUtils: getBtEnabledContainers(): btContainers = []
11-14 10:55:23.472 15152-15178/? E/BluetoothRemoteDevices: aclStateChangeCallback: State:Connected to Device:18:7A:93:4C:69:XX, linktype is 2
11-14 10:55:23.479 15152-15178/? D/BluetoothUtils: getBtEnabledContainers(): btContainers = []
11-14 10:55:23.481 15152-15178/? W/bt_btif: btif_dm_upstreams_cback  ev: BTA_DM_BUSY_LEVEL_EVT
11-14 10:55:23.482 15152-15178/? W/bt_btif: BTA_DM_BUSY_LEVEL_EVT :: p_data->busy_level.level_flags : 0x0
11-14 10:55:23.484 18107-18107/? D/oneconnect[1.6.05-45_2]: BluetoothHelper.mBtStateReceiver -  [action]android.bluetooth.device.action.ACL_CONNECTED [connState]0[address] - ($)
11-14 10:55:23.488 3763-3848/? D/CompatibilityInfo: mCompatibilityFlags - 0
11-14 10:55:23.488 3763-3848/? D/CompatibilityInfo: applicationDensity - 480
11-14 10:55:23.488 3763-3848/? D/CompatibilityInfo: applicationScale - 1.0
11-14 10:55:23.493 18107-18133/? D/BluetoothA2dp: getState(18:7A:93:4C:69:XX)
11-14 10:55:23.493 3763-3763/? D/KnoxKeyguardUpdateMonitor: BroadcastReceiver onReceive
11-14 10:55:23.493 3763-3763/? D/KnoxKeyguardUpdateMonitor: BroadcastReceiver onReceive action: android.bluetooth.device.action.ACL_CONNECTED
11-14 10:55:23.493 3763-3763/? D/KnoxKeyguardUpdateMonitor: BroadcastReceiver ACTION_ACL_CONNECTED
11-14 10:55:23.503 3763-4488/? D/CompatibilityInfo: mCompatibilityFlags - 0
11-14 10:55:23.503 3763-4488/? D/CompatibilityInfo: applicationDensity - 480
11-14 10:55:23.503 3763-4488/? D/CompatibilityInfo: applicationScale - 1.0
11-14 10:55:23.513 15152-15342/? D/A2dpStateMachine: getConnectionState: 0
11-14 10:55:23.514 3763-4436/? D/CompatibilityInfo: mCompatibilityFlags - 0
11-14 10:55:23.514 3763-4436/? D/CompatibilityInfo: applicationDensity - 480
11-14 10:55:23.515 3763-4436/? D/CompatibilityInfo: applicationScale - 1.0
11-14 10:55:23.519 18107-18133/? D/BluetoothHeadset: getConnectionState() in if statement
11-14 10:55:23.519 15152-15956/? W/HeadsetService: getConnectionState
11-14 10:55:23.523 15152-15956/? W/HeadsetService: get Service
11-14 10:55:23.523 15152-15956/? W/HeadsetService: service is not null
11-14 10:55:23.524 4983-4983/? W/SearchService: Abort, client detached.
11-14 10:55:23.524 15152-15956/? D/HeadsetService: enter getConnectionState
11-14 10:55:23.525 15152-15956/? D/HeadsetService: getConnectionState is 0
11-14 10:55:23.525 15152-15956/? W/HeadsetService: ret = 0
11-14 10:55:23.527 4983-4983/? I/BistoWorker: handleCommonBroadcastIntent: android.bluetooth.device.action.ACL_CONNECTED
11-14 10:55:23.532 15152-15354/? E/BluetoothRemoteDevices: getGearIsConnected false
11-14 10:55:23.532 18107-18133/? D/oneconnect[1.6.05-45_2]: BluetoothActionHelper.isConnected - ($)69:D4 NO profile connected
11-14 10:55:23.533 18107-18133/? D/oneconnect[1.6.05-45_2]: BluetoothActionHelper.isA2dpSinkConnected - ($)69:D4 mA2dpSlink not connected
11-14 10:55:23.542 4983-4983/? I/BistoWorker: Not a bisto device: 18:7A:93:4C:69:D4

理想情况下,当我请求连接时,它应该与设备连接。我不知道为什么android蓝牙在不请求连接的情况下与设备连接。

有人对此有任何想法吗?

=========更新==========

我发现的另一件事是当我尝试连接设备(规模)时,它给了我

11-15 14:46:38.473 3770-3770/? D/KnoxKeyguardUpdateMonitor: BroadcastReceiver onReceive action: android.bluetooth.device.action.ACL_CONNECTED

但在我的服务上它返回以下值。

11-15 14:46:38.493 23031-23101/? D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=8 device=18:7A:93:4B:E1:XX

在 133 GATT_FAILURE 的情况下,我通过尝试 4 次重新连接来处理它。但是还是报了133错误。

【问题讨论】:

【参考方案1】:

您的连接请求中可能已将 autoconnected 设置为 true。请注意,mBluetoothGatt = device.connectGatt(this, false, mGattCallback);autoconnect 标志作为第二个参数。

请检查 [connectGatt](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback))。

【讨论】:

我设置为假。 mBluetoothGatt = device.connectGatt(getApplicationContext(), false, mBluetoothGattCallback);

以上是关于设备断开连接后收到 android.bluetooth.device.action.ACL_CONNECTED的主要内容,如果未能解决你的问题,请参考以下文章

所选设备已断开连接,无法再从此机器访问

BLE外围设备断开

如果在 iPhone 的蓝牙设置中建立连接,我如何收到通知?

来自 2 个 BLE 设备的 ios 通知

tcp连接的断开

设备与 GATT 服务器断开连接