Android 4.4.4 Moto G Bluetooth LE 重新连接问题

标签 android bluetooth bluetooth-lowenergy android-bluetooth motorola

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

我的 BLE 外围设备在应用程序使用过程中连接和断开连接多次。这工作正常,但有时会出现应用程序/手机不再重新连接到外围设备的情况。

所有 gatt 命令都在主线程上运行,eg.

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有关?!

最佳答案

我认为不会有像“使用主线程”这样简单的答案,一切都很好。但我可以给你一些我在使用糟糕的 Android BLE 时收集到的提示:

  • BT 堆栈在不同的手机上会有所不同,不幸的是,如果我们谈论 BLE,Moto G 是最糟糕的手机之一……有多糟糕? Tile 应用程序甚至在其 F.A.Q What Android phones will Tile work with 中声明:

will work only with Samsung Galaxy S5, HTC One M8, HTC One, LG Nexus 4, LG Nexus 5, LG Nexus 6, Samsung Note 4, Motorola Moto X and certainly will not work with 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.

关于Android 4.4.4 Moto G Bluetooth LE 重新连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29495989/

相关文章:

Java:异常本身为空

android - 安卓模拟器中的蓝牙

android - Samsung Android BLE 多重读写

bluetooth - 蓝牙 : Max number of packets in Connection interval

swift - 在 swift 中收听事件舞会蓝牙外围设备

android - EditText 或 TextView 的 setText 方法在 switch 语句内不起作用

android - 如何在 PendingIntents 中使用 requestCode

java - 发布到主循环程序,执行顺序

android - 更改 ListView 项目的文本颜色

iOS CBPeripheral 连接问题