• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Bluetooth BLE scan stops when advertising stops

kenhue

Lurker
I have an Android 6 - level 23 application running on mobile devices that both concurrently advertises and scans BLE connectionless packets.

ISSUE:

I find that when I call stopAdvertising(), the continuous running BLE scan operation is halted or stops working for 1-4 seconds, before resuming again. I know this because I can readily see the continually received ad packets every 0.10 second are not received for 1-4 seconds. This implies the scan operation is halted or stopped when the advertise operation is programmatically stopped.

How can I periodically start and stop BLE advertising without adversely messing up the BLE scanning operation?

I tried developing my application using different Android version APIs with the same annoying scan halt problem:
Android 6 - level 23
Android 8 level 26


Just for reference, here's some snippets of Android 6 code:

// 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);
 
Back
Top Bottom