Android 4.4.4 Moto G蓝牙LE重新连接问题

时间:2015-04-07 16:00:45

标签: android bluetooth bluetooth-lowenergy android-bluetooth motorola

我的应用程序在运行Android 4.3的三星S3上运行良好但是我在运行4.4.4的Moto G上遇到问题

我的BLE外围设备在应用程序使用期间多次连接和断开连接。这样可以正常工作,但有时候app / phone不再重新连接到外围设备。

所有gatt命令都在主线程上运行,例如

final BluetoothGatt gat = gatt;
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
  // This code will be executed on the main thread
  if (Looper.myLooper() == Looper.getMainLooper()) {
    Log.e(TAG, "mGattCallback disconnect2: NOW ON MAIN THREAD :)");
  }
  gat.disconnect();
  }
});

并且外围设备断开正常。当发生这种情况并且我无法重新连接到外围设备时,我会得到大量的日志:

04-07 16:57:56.798: I/bt-hci(2127): BLE HCI(id=62) event = 0x02)
04-07 16:57:56.798: I/bt-hci(2127): btu_ble_process_adv_pkt
04-07 16:57:56.833: I/bt-hci(2127): BLE HCI(id=62) event = 0x02)
04-07 16:57:56.833: I/bt-hci(2127): btu_ble_process_adv_pkt
04-07 16:57:56.871: I/bt-hci(2127): BLE HCI(id=62) event = 0x02)
04-07 16:57:56.871: I/bt-hci(2127): btu_ble_process_adv_pkt
04-07 16:57:56.906: I/bt-hci(2127): BLE HCI(id=62) event = 0x02)
04-07 16:57:56.906: I/bt-hci(2127): btu_ble_process_adv_pkt
04-07 16:57:56.941: I/bt-hci(2127): BLE HCI(id=62) event = 0x02)
04-07 16:57:56.941: I/bt-hci(2127): btu_ble_process_adv_pkt
04-07 16:57:56.977: I/bt-hci(2127): BLE HCI(id=62) event = 0x02)
04-07 16:57:56.977: I/bt-hci(2127): btu_ble_process_adv_pkt
04-07 16:57:57.016: I/bt-hci(2127): BLE HCI(id=62) event = 0x02)
04-07 16:57:57.016: I/bt-hci(2127): btu_ble_process_adv_pkt

我需要退出应用程序,再次关闭蓝牙,然后重新开始正常工作。

任何已知问题,提示或建议?

由于

编辑----------- 经过一些测试后,似乎让应用程序继续运行,最终我得到了以下日志,然后我的外围设备可以重新连接:

04-13 19:11:53.973: I/bt-hci(2034): BLE HCI(id=62) event = 0x02)
04-13 19:11:53.973: I/bt-hci(2034): btu_ble_process_adv_pkt
04-13 19:11:54.076: I/bt-hci(2034): BLE HCI(id=62) event = 0x02)
04-13 19:11:54.076: I/bt-hci(2034): btu_ble_process_adv_pkt
04-13 19:11:55.986: I/bt-hci(2034): BLE HCI(id=62) event = 0x02)
04-13 19:11:55.986: I/bt-hci(2034): btu_ble_process_adv_pkt
04-13 19:11:56.087: I/bt-hci(2034): BLE HCI(id=62) event = 0x02)
04-13 19:11:56.087: I/bt-hci(2034): btu_ble_process_adv_pkt
04-13 19:11:56.629: I/bt-hci(2034): BLE HCI(id=62) event = 0x02)
04-13 19:11:56.629: I/bt-hci(2034): btu_ble_process_adv_pkt
04-13 19:11:56.734: I/bt-hci(2034): BLE HCI(id=62) event = 0x02)
04-13 19:11:56.734: I/bt-hci(2034): btu_ble_process_adv_pkt
04-13 19:11:58.925: D/MDMCTBK(275): reply_len: 40 reply is = IFNAME=wlan0 <3>CTRL-EVENT-SCAN-RESULTS 
04-13 19:11:58.925: D/MDMCTBK(275): Event received = CTRL-EVENT-SCAN-RESULTS 
04-13 19:11:58.926: D/WifiStateMachine(1010): handleMessage: E msg.what=147461
04-13 19:11:58.926: D/WifiStateMachine(1010): processMsg: DisconnectedState
04-13 19:11:58.926: D/WifiStateMachine(1010): processMsg: ConnectModeState
04-13 19:11:58.926: D/WifiStateMachine(1010): processMsg: DriverStartedState
04-13 19:11:58.927: D/WifiStateMachine(1010): processMsg: SupplicantStartedState
04-13 19:11:58.928: D/TCMD(4253): NL - Read 56 bytes from update socket.
04-13 19:11:58.928: D/TCMD(4253): NL - message type is RTM_NEWLINK
04-13 19:11:58.928: D/TCMD(4253): Listening for incoming client connection request
04-13 19:35:18.787: V/AlarmManager(1010): sending alarm Alarm{42b84cc0 type 2 com.google.android.gms}
04-13 19:35:18.787: V/AlarmManager(1010): sending alarm Alarm{42b83a00 type 0 android}
04-13 19:11:58.941: D/WifiStateMachine(1010): handleMessage: X
04-13 19:12:00.615: D/WifiStateMachine(1010): handleMessage: E msg.what=131143
04-13 19:12:00.615: D/WifiStateMachine(1010): processMsg: DisconnectedState
04-13 19:12:00.616: D/WifiStateMachine(1010): processMsg: ConnectModeState
04-13 19:12:00.617: D/WifiStateMachine(1010): processMsg: DriverStartedState
04-13 19:12:00.628: D/WifiStateMachine(1010): handleMessage: X
04-13 19:12:01.425: D/MDMCTBK(275): reply_len: 40 reply is = IFNAME=wlan0 <3>CTRL-EVENT-BSS-REMOVED 1
04-13 19:12:01.425: D/MDMCTBK(275): Event received = CTRL-EVENT-BSS-REMOVED 1
04-13 19:12:01.425: D/MDMCTBK(275): reply_len: 40 reply is = IFNAME=wlan0 <3>CTRL-EVENT-SCAN-RESULTS 
04-13 19:12:01.425: D/MDMCTBK(275): Event received = CTRL-EVENT-SCAN-RESULTS 
04-13 19:12:01.425: D/WifiStateMachine(1010): handleMessage: E msg.what=147461
04-13 19:12:01.426: D/WifiStateMachine(1010): processMsg: DisconnectedState
04-13 19:12:01.426: D/WifiStateMachine(1010): processMsg: ConnectModeState
04-13 19:12:01.426: D/WifiStateMachine(1010): processMsg: DriverStartedState
04-13 19:12:01.426: D/WifiStateMachine(1010): processMsg: SupplicantStartedState
04-13 19:12:01.428: D/MDMCTBK(275): reply_len: 40 reply is = IFNAME=p2p0 <3>CTRL-EVENT-BSS-REMOVED 1 
04-13 19:12:01.428: D/MDMCTBK(275): Event received = CTRL-EVENT-BSS-REMOVED 1 
04-13 19:12:01.428: D/TCMD(4253): NL - Read 56 bytes from update socket.
04-13 19:12:01.428: D/TCMD(4253): NL - message type is RTM_NEWLINK
04-13 19:12:01.428: D/TCMD(4253): Listening for incoming client connection request
04-13 19:12:01.444: D/WifiStateMachine(1010): handleMessage: X

看起来它与WiFi有关吗?!

2 个答案:

答案 0 :(得分:4)

我认为没有一个简单的答案,比如&#34;使用主线程&#34;一切都很好。但是我可以给你一些我在使用糟糕的Android BLE时收集的提示:

  

仅适用于三星Galaxy S5,HTC One M8,HTC One,LG Nexus 4,LG Nexus 5,LG Nexus 6,Samsung Note 4,摩托罗拉Moto X 当然不适用于Moto G

Bluedroid continues to mature and stabilize; there were 565 commits to the bluedroid project alone from 4.4 -> 5.0, compared with 52 commits from 4.3 -> 4.4, and 47 commits from 4.2 -> 4.3.* This is an area of heavy activity within AOSP right now.

答案 1 :(得分:2)

这是一个MotoG特定的问题,我之前在MotoG设备上遇到过相同的问题。从蓝牙低功耗不够成熟时起,Wifi和蓝牙功能会对该特定设备产生相互干扰。

从之前的R&amp; D我做过,不确定这是否是操作系统版本&amp;设备特定组合但 有一些与蓝牙和Wifi相关的问题,更多的是蓝牙低功耗和Wifi,许多都是特定于设备的。

关于您所面临的问题, Android开源项目 - 问题跟踪器和其他博客也存在问题;

Issue 39995
Issue 41631

Nexus 5, Nexus 4 and Nexus 7 (2013) Android 4.4 Bluetooth Issues
[虽然我在Nexus 5中没有遇到过这个问题]

无论连接数量多少,Wifi都会影响蓝牙低功耗。此外,连接的重新连接和超时也可以是硬件方面的属性。

您的代码很好,希望您节省一些时间,我花了一些时间在MotoG和其他一些设备上;正是通过BluetoothGatt和iBeacon框架与ble-devices交互时蓝牙低能耗和wifi干扰的情况。