smartboy
我们的设备用GR5515芯片蓝牙。我们开发的APK上有时候蓝牙断开失败了。 断开是设备日志打印这样的错误 APP_E: (llc_con_upd_patch.c Line:159) [WARNING] Param0:9,Param1:8
EVT_Handler不处理disconnected时间,反而connection updated事件发生了。 APK上显示正常断开回复了。可以教一下这是什么原因,有没有解决方法?
zhongchengzhi
smartboy
I/System.out: Start connecting...
I/System.out: Ble connect started
D/BleGatt: setupReceiver()
D/BleGatt: connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
D/BluetoothGatt: connect() - device: CF:15:30:**:**:**, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=aeab3e84-c52e-4777-9991-2b4000ea79ce
D/BleGatt: gatt.close()
D/BluetoothGatt: close()
D/BluetoothGatt: unregisterApp() - mClientIf=0
D/BleGatt: wait(200)
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=17
E/BluetoothGatt: Bad connection state: 4
D/BleGatt: connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
D/BluetoothGatt: connect() - device: CF:15:30:**:**:**, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=db21a755-08aa-4246-b735-0894c92b5d60
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=18
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=17 device=CF:15:30:**:**:**
D/BleGatt: [Callback] Connection state changed with status: 0 and new state: 2 (CONNECTED)
I/BleGatt: Connected to CF:15:30:00:00:0D
I/System.out: ConnectionStateChanged: status = 0, newState = 2, 1714978179889
D/BluetoothGatt: discoverServices() - device: CF:15:30:**:**:**
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=18 device=CF:15:30:**:**:**
D/BleGatt: [Callback] Connection state changed with status: 0 and new state: 2 (CONNECTED)
I/BleGatt: Connected to CF:15:30:00:00:0D
I/System.out: ConnectionStateChanged: status = 0, newState = 2, 1714978179917
W/TaskQueue: The task is not idle. DO NOT call start() again, from onConnectionStateChange(BleRemoteDevice.java:675)<-onConnectionStateChange(GattCallbackDispatcher.java:41)<-onConnectionStateChange(BleGattX.java:538)
I/System.out: Connected again error:1714978179917
D/BluetoothGatt: onConnectionUpdated() - Device=CF:15:30:**:**:** interval=6 latency=0 timeout=500 status=0
D/BluetoothGatt: onConnectionUpdated() - Device=CF:15:30:**:**:** interval=6 latency=0 timeout=500 status=0
I/BleGatt: Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
I/BleGatt: Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
D/BluetoothGatt: onConnectionUpdated() - Device=CF:15:30:**:**:** interval=40 latency=0 timeout=500 status=0
D/BluetoothGatt: onConnectionUpdated() - Device=CF:15:30:**:**:** interval=40 latency=0 timeout=500 status=0
I/BleGatt: Connection parameters updated (interval: 50.0ms, latency: 0, timeout: 5000ms)
I/BleGatt: Connection parameters updated (interval: 50.0ms, latency: 0, timeout: 5000ms)
D/BluetoothGatt: onConnectionUpdated() - Device=CF:15:30:**:**:** interval=160 latency=0 timeout=400 status=0
D/BluetoothGatt: onConnectionUpdated() - Device=CF:15:30:**:**:** interval=160 latency=0 timeout=400 status=0
I/BleGatt: Connection parameters updated (interval: 200.0ms, latency: 0, timeout: 4000ms)
I/BleGatt: Connection parameters updated (interval: 200.0ms, latency: 0, timeout: 4000ms)
E/GattDiscover: finished with: resultCode = [-3], rootCause = [[GattDiscover]: Timeout]
E/TaskQueue: finished with: resultCode = [-3], rootCause = [[GattDiscover]: Timeout]
V/BleGatt: Disconnecting...
D/BluetoothGatt: cancelOpen() - device: CF:15:30:**:**:**
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=18 device=CF:15:30:**:**:**
D/BleGatt: [Callback] Connection state changed with status: 0 and new state: 0 (DISCONNECTED)
I/System.out: ConnectionStateChanged: status = 0, newState = 0, 1714978210905
D/BluetoothGatt: refresh() - device: CF:15:30:**:**:**
V/BleGatt: Refresh device cache: true
V/BleGatt: Close gatt and dispose resource.
D/BleGatt: cleanReceiver()
D/BluetoothGatt: close()
D/BluetoothGatt: unregisterApp() - mClientIf=18
D/BluetoothGatt: onConnectionUpdated() - Device=CF:15:30:**:**:** interval=6 latency=0 timeout=500 status=0
I/BleGatt: Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
D/BluetoothGatt: onConnectionUpdated() - Device=CF:15:30:**:**:** interval=160 latency=0 timeout=400 status=0
I/BleGatt: Connection parameters updated (interval: 200.0ms, latency: 0, timeout: 4000ms)
AndroidStudio连接错误时报告这样的。 connected回应两次。然后自动断开了。 但是设备依然留着连接状态, APK上蓝牙搜不到的。
zhongchengzhi
您好,
1、关于设备依然留着连接状态,APK上搜不到蓝牙:是因为你连接了两次,mClientIf=17和mClientIf=18,只有mClientIf=18断开了,mClientIf=17还在。您这边可以检查下为啥会连接2次。
2、mClientIf=17, Bad connection state: 4可参考以下代码: http://androidxref.com/9.0.0_r3/xref/frameworks/base/core/java/android/bluetooth/BluetoothGatt.java
smartboy
谢谢, 问题解决了。 原来代码里面有连接两次部分。
不知道为什么这样链接了。 可以请教这个connect(0)和connect(1)有什么区别吗?
public void connectDevice() { if (!BLERequest.isBLEEnabled(appCtx)) { return; } if (targetDevice != null) { targetDevice.getGatt().connect(0).startProcedure(); if (!targetDevice.getGatt().connect(1).isStarted()) { targetDevice.getGatt().connect(1) .setTimeout(30000) .startProcedure(); } }}
打开微信,使用“扫一扫”即可关注