5

What's the purpose of setReportDelay for BluetoothLeScanner in Android? I can't imagine why one would get reports with delay...

Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103

3 Answers3

2

From Android Official Site:

setReportDelay() takes reportDelayMillis parameter where reportDelayMillis is:

Delay of report in milliseconds. Set to 0 to be notified of results immediately. Values > 0 causes the scan results to be queued up and delivered after the requested delay or when the internal buffers fill up

coming to your question:

What's the purpose of setReportDelay for BluetoothLeScanner in Android? I can't imagine why one would get reports with delay...|

As i understood the purpose of this is that sometimes when you scan for a very short period of time, not all the devices/beacons can be found, but on the second scan another one can be cought while scanning.

Ex: Suppose you have three beacons and you made two different scans for 1s. On the first scan only single beacon is found, but on the second other beacons found too. Setting a delay will queue all of them and you will be able to show all of them. Otherwise sometimes single beacon, sometimes all of them and sometimes two of them will be shown.(This is related mostly with the frequency they transmit)

You can use also Lists for this purpose, so when a beacon is found you add them to the list and show them after some delay(using Handler/Timer). But this will require more work. So it is probably simplified with this function

hrskrs
  • 4,447
  • 5
  • 38
  • 52
2

setReportDelay() > 0 causes the scanner to queue up results and then fire the onBatchScanResults() from ScanCallback rather than the normal onScanResult().

This is quite useful if you need to do a UI update every few seconds: rather than refreshing your UI every time an announcement packet arrives, you can simply delay the results. Also, you get a more complete result set.

Note that your device need to be able to support this. See

http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#isOffloadedScanBatchingSupported()

mogoman
  • 2,286
  • 24
  • 28
0

Different devices scan slightly differently. When scanning some will return the same found device multiple times per scan.

If you set a delay, Android will create a queue, and all duplicates are filtered out before that list of devices in the queue is returned.

Martin Konecny
  • 57,827
  • 19
  • 139
  • 159