【问题标题】:Android app's Bluetooth BLE scan stop when advertising stops. Why?广告停止时,Android 应用的蓝牙 BLE 扫描停止。为什么?
【发布时间】:2019-11-20 15:31:28
【问题描述】:

我有一个运行在移动设备上的 Android 6 - 级别 23 应用程序,它同时发布和扫描 BLE 无连接数据包。

问题:

我发现当我调用 stopAdvertising() 时,连续运行的 BLE 扫描操作会暂停或停止工作 1-4 秒,然后再次恢复。我知道这一点是因为我可以很容易地看到每 0.10 秒连续收到的广告数据包在 1-4 秒内没有收到。这意味着当广告操作以编程方式停止时,扫描操作将暂停或停止。

我如何才能定期启动和停止 BLE 广告不会对 BLE 扫描操作造成不利影响

我尝试使用不同的 Android 版本 API 开发我的应用程序,但遇到了同样烦人的扫描停止问题: 安卓 6 - 23 级 Android 8 26 级

仅供参考,这里有一些Android 6代码的sn-ps:

       // create advertiser and save in list, so advertising instance can be stopped in future.           
       mBluetoothAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();

       // start advertising!
       mBluetoothAdvertiser.startAdvertising( settings, data, mBluetoothAdvertiseCallback );

       // do some work...

      // TESTED BAD - the call below causes the BLE scan operation to halt for 1-4 seconds.
       mBluetoothAdvertiser.stopAdvertising(mBluetoothAdvertiseCallback);

【问题讨论】:

    标签: android bluetooth bluetooth-lowenergy scanning


    【解决方案1】:

    在 Android 的蓝牙堆栈中,扫描和广告是完全独立的。所有操作都简单地发送到蓝牙芯片,并由其固件进行扫描和广告。

    通常只有一个无线电的蓝牙芯片需要安排扫描和广告,因为只能同时执行一项操作。

    显然你看到了这个效果。不同蓝牙芯片制造商使用的调度算法是专有的,通常不公开。您必须询问您正在使用的特定设备的制造商为什么它们会以特定方式运行。

    然而,Android 会发送扫描间隔的提示。在 Android 中,间隔是 5 秒,所以这可能会影响您的结果。

    【讨论】:

    • 感谢 Emil 的回答! -肯
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多