我正在研究蓝牙低功耗设备(体重秤)。
我发现了一些事情。当我尝试与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蓝牙在没有请求连接的情况下与设备连接。
有没有人对此有任何想法?
====== UPDATE ==========
我发现的另一件事是当我尝试连接设备(比例尺)时,它给了我
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错误。
答案 0 :(得分:0)
您的连接请求中可能已将autoconnected设置为true。请注意mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
将第autoconnect
个标记作为第二个参数。
请检查[connectGatt](https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#connectGatt(android.content.Context,布尔值,android.bluetooth.BluetoothGattCallback))。