Added in API level 21

Builder


class Builder
kotlin.Any
   ↳ android.bluetooth.le.ScanSettings.Builder

Builder for ScanSettings.

Summary

Public constructors

Public methods
ScanSettings!

Build ScanSettings.

ScanSettings.Builder!
setCallbackType(callbackType: Int)

Set callback type for Bluetooth LE scan.

ScanSettings.Builder!
setLegacy(legacy: Boolean)

Set whether only legacy advertisements should be returned in scan results.

ScanSettings.Builder!
setMatchMode(matchMode: Int)

Set match mode for Bluetooth LE scan filters hardware match.

ScanSettings.Builder!
setNumOfMatches(numOfMatches: Int)

Set the number of matches for Bluetooth LE scan filters hardware match.

ScanSettings.Builder!
setPhy(phy: Int)

Set the Physical Layer to use during this scan.

ScanSettings.Builder!
setReportDelay(reportDelayMillis: Long)

Set report delay timestamp for Bluetooth LE scan.

ScanSettings.Builder!
setScanMode(scanMode: Int)

Set scan mode for Bluetooth LE scan.

Public constructors

Builder

Added in API level 21
Builder()

Public methods

build

Added in API level 21
fun build(): ScanSettings!

Build ScanSettings.

Exceptions
java.lang.IllegalArgumentException if the settings cannot be built.

setCallbackType

Added in API level 23
fun setCallbackType(callbackType: Int): ScanSettings.Builder!

Set callback type for Bluetooth LE scan.

Parameters
callbackType Int: The callback type flags for the scan.
Exceptions
java.lang.IllegalArgumentException If the callbackType is invalid.

setLegacy

Added in API level 26
fun setLegacy(legacy: Boolean): ScanSettings.Builder!

Set whether only legacy advertisements should be returned in scan results. Legacy advertisements include advertisements as specified by the Bluetooth core specification 4.2 and below. This is true by default for compatibility with older apps.

Parameters
legacy Boolean: true if only legacy advertisements will be returned

setMatchMode

Added in API level 23
fun setMatchMode(matchMode: Int): ScanSettings.Builder!

Set match mode for Bluetooth LE scan filters hardware match.

Parameters
matchMode Int: The match mode can be one of ScanSettings.MATCH_MODE_AGGRESSIVE or ScanSettings.MATCH_MODE_STICKY
Exceptions
java.lang.IllegalArgumentException If the matchMode is invalid.

setNumOfMatches

Added in API level 23
fun setNumOfMatches(numOfMatches: Int): ScanSettings.Builder!

Set the number of matches for Bluetooth LE scan filters hardware match.

Parameters
numOfMatches Int: The num of matches can be one of android.bluetooth.le.ScanSettings#MATCH_NUM_ONE_ADVERTISEMENT or android.bluetooth.le.ScanSettings#MATCH_NUM_FEW_ADVERTISEMENT or android.bluetooth.le.ScanSettings#MATCH_NUM_MAX_ADVERTISEMENT
Exceptions
java.lang.IllegalArgumentException If the matchMode is invalid.

setPhy

Added in API level 26
fun setPhy(phy: Int): ScanSettings.Builder!

Set the Physical Layer to use during this scan. This is used only if android.bluetooth.le.ScanSettings.Builder#setLegacy is set to false. android.bluetooth.BluetoothAdapter#isLeCodedPhySupported may be used to check whether LE Coded phy is supported by calling android.bluetooth.BluetoothAdapter#isLeCodedPhySupported. Selecting an unsupported phy will result in failure to start scan.

Parameters
phy Int: Can be one of BluetoothDevice.PHY_LE_1M, android.bluetooth.BluetoothDevice#PHY_LE_CODED or ScanSettings.PHY_LE_ALL_SUPPORTED

setReportDelay

Added in API level 21
fun setReportDelay(reportDelayMillis: Long): ScanSettings.Builder!

Set report delay timestamp for Bluetooth LE scan. If set to 0, you will be notified of scan results immediately. If > 0, scan results are queued up and delivered after the requested delay or 5000 milliseconds (whichever is higher). Note scan results may be delivered sooner if the internal buffers fill up.

Parameters
reportDelayMillis Long: how frequently scan results should be delivered in milliseconds
Exceptions
java.lang.IllegalArgumentException if reportDelayMillis < 0

setScanMode

Added in API level 21
fun setScanMode(scanMode: Int): ScanSettings.Builder!

Set scan mode for Bluetooth LE scan.

Parameters
scanMode Int: The scan mode can be one of ScanSettings.SCAN_MODE_LOW_POWER, ScanSettings.SCAN_MODE_BALANCED or android.bluetooth.le.ScanSettings#SCAN_MODE_LOW_LATENCY.
Exceptions
java.lang.IllegalArgumentException If the scanMode is invalid.