android - 循环启动和停止时蓝牙 LE 广告失败

标签 android bluetooth-lowenergy android-bluetooth

我已经尝试过蓝牙 LE 广告,即使用 Android 手机作为 BLE“外围”设备。启动和停止持续的广告一次工作正常,但如果我想实际传输一些不同的数据,我需要在一个周期中启动、停止和重新启动广告,并始终更改广告包。

我当然在使用这些方法:
BluetoothLeAdvertiser.startAdvertising()
BluetoothLeAdvertiser.stopAdvertising()

至少在摩托罗拉 Moto G 4G 2nd gen 上。 (XT1072) 在 Android 5.0.2 中,循环只运行了一段时间,然后蓝牙堆栈出现问题,无法再开始新的广告。当快速运行循环时,这种情况发生得很快,如果运行缓慢,则需要更多时间,因此这可能与某些缓冲区填满有关。

我的问题是:除摩托罗拉外,其他设备也会出现这种情况吗?

(当然欢迎任何其他相关评论。)

从理论上讲,它可能取决于某些制造商特定的 HAL 实现等。所以我想知道我是否应该购买另一台设备来解决这个问题,因为谷歌/摩托罗拉的任何修复当然都需要一些时间.

这个测试应用。可以用来试试这个:

https://bitbucket.org/MarkusKauppinen/bleadvertisertest

如果一切顺利,它会很乐意一直做广告,如果这个问题再次出现,它会在几分钟左右显示一个对话框。如果您的设备根本不支持蓝牙 LE 广告或 BLE,它就会崩溃。 (这只是一个快速而简单的测试应用程序。)

重现此问题的另一种简单方法是从 https://github.com/devunwired/accessory-samples 运行“bluetoothadvertiser”应用程序然后快速点击 UI 上的“更新广告”按钮一会儿。

其他详细信息:

蓝牙 LE 外设模式支持(广告需要)已添加到 Lollipop 中,但在 4.x 中不可用。只有某些设备具有外设模式支持。兼容性至少涵盖在:

https://altbeacon.github.io/android-beacon-library/beacon-transmitter-devices.html Chipsets/Devices supporting Android 5 BLE peripheral mode chipsets supporting BLE peripheral role on Android 5

例如,这些设备应该支持:Motorola Moto E 4G (2015)、Motorola Moto G 4G(第 2 代)、Sony Xperia M4 Aqua、ZTE Blade S6、Motorola Moto X (2014)、Samsung Galaxy S6、谷歌 Nexus 6、谷歌 Nexus 9、HTC One M9、三星 Galaxy S6 Edge。

至于“肮脏的细节”,我总能在发生这种情况之前在 LogCat 中看到“GKI_Exception”:

GKI_exception(): 65524 getbuf: out of buffers

在第一个“GKI_Exception”之后不久,广告因 AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR 失败。这条线...

E/BtGatt.btif? ### ASSERT : external/bluetooth/bluedroid/main/../btif/src/btif_gatt_client.c line 803 Context transfer failed! (3) ###

...可能相关,但我不熟悉 BlueDroid。所说的断言在这里:

https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.0.2_r1/btif/src/btif_gatt_client.c#803

一些可能相关的问题:
https://code.google.com/p/android/issues/detail?id=65455 <-- 我给这个添加了一些评论和日志文件。
https://code.google.com/p/android-developer-preview/issues/detail?id=1753
Scanning large number of BLE Tags
Bluetooth Crash on Samsung S4

最佳答案

我在 Moto G 2nd Gen 上测试了您的应用,遇到了同样的问题。

我在运行 Android 6.0 的 Nexus 9 平板电脑上尝试过,我无法重现错误,但它似乎可以工作。同样在装有 Android 5.1.1 的 Nexus 播放器上,它似乎可以毫无问题地运行。 因此,这要么真的是 Moto G 的问题,要么 - 我认为更有可能 - Android 5.0.2 的错误已在更高版本中解决。

关于android - 循环启动和停止时蓝牙 LE 广告失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32656938/

相关文章:

ios - 如何在iOS中通过BLE获取设备的MAC

android - 如何读取我的 BLE 设备的所有特征值?

android - MAC地址在Android中是否随时间变化

android - fragment 中的蓝牙启用 Intent

android - Volley 以 utf-8 格式发送请求

android - 将 RelativeLayout 分成两半

android - 刷新 fragment 不再起作用?

android - 为什么android中xml的style属性没有命名空间

c# - 发现并连接到 BLE 设备

Android蓝牙MAC获取的是02 :00:00:00:00:00