Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

```
class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.bluetooth.le.ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#) |

Builder for `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings`.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#Builder()()` Create an empty builder. |

| Public methods ||
|---|---|
| [ScanSettings](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings)! | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#build()()` Build `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings`. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#)! | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setCallbackType(kotlin.Int)(callbackType: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set callback type for Bluetooth LE scan. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#)! | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setLegacy(kotlin.Boolean)(legacy: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Set whether only legacy advertisements should be returned in scan results. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#)! | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setMatchMode(kotlin.Int)(matchMode: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set match mode for Bluetooth LE scan filters hardware match. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#)! | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setNumOfMatches(kotlin.Int)(numOfMatches: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the number of matches for Bluetooth LE scan filters hardware match. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#)! | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setPhy(kotlin.Int)(phy: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set the Physical Layer to use during this scan. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#)! | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setReportDelay(kotlin.Long)(reportDelayMillis: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)` Set report delay timestamp for Bluetooth LE scan. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#) | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setRssiThreshold(kotlin.Int)(rssiThreshold: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets the RSSI threshold. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#)! | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setScanMode(kotlin.Int)(scanMode: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Set scan mode for Bluetooth LE scan. |
| [ScanSettings.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#) | `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setScanType(kotlin.Int)(scanType: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets the scan type. |

## Public constructors

### Builder

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Builder()
```

Create an empty builder.

## Public methods

### build

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun build(): ScanSettings!
```

Build `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings`.

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | if the settings cannot be built. |

### setCallbackType

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setCallbackType(callbackType: Int): ScanSettings.Builder!
```

Set callback type for Bluetooth LE scan.

| Parameters ||
|---|---|
| `callbackType` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The callback type flags for the scan. |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | If the `callbackType` is invalid. |

### setLegacy

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): true if only legacy advertisements will be returned |

### setMatchMode

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setMatchMode(matchMode: Int): ScanSettings.Builder!
```

Set match mode for Bluetooth LE scan filters hardware match.

| Parameters ||
|---|---|
| `matchMode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The match mode can be one of `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#MATCH_MODE_AGGRESSIVE:kotlin.Int` or `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#MATCH_MODE_STICKY:kotlin.Int` |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | If the `matchMode` is invalid. |

### setNumOfMatches

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setNumOfMatches(numOfMatches: Int): ScanSettings.Builder!
```

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

| Parameters ||
|---|---|
| `numOfMatches` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The num of matches can be one of `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#MATCH_NUM_ONE_ADVERTISEMENT:kotlin.Int` or `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#MATCH_NUM_FEW_ADVERTISEMENT:kotlin.Int` or `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#MATCH_NUM_MAX_ADVERTISEMENT:kotlin.Int` |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | If the `matchMode` is invalid. |

### setPhy

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setPhy(phy: Int): ScanSettings.Builder!
```

Set the Physical Layer to use during this scan. This is used only if `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#setLegacy(kotlin.Boolean)` is set to false. `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothAdapter.html#isLeCodedPhySupported()` may be used to check whether LE Coded phy is supported by calling `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothAdapter.html#isLeCodedPhySupported()`. Selecting an unsupported phy will result in failure to start scan.

| Parameters ||
|---|---|
| `phy` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): Can be one of `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice.html#PHY_LE_1M:kotlin.Int`, `https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice.html#PHY_LE_CODED:kotlin.Int` or `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#PHY_LE_ALL_SUPPORTED:kotlin.Int` |

### setReportDelay

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): how frequently scan results should be delivered in milliseconds |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | if `reportDelayMillis` \< 0 |

### setRssiThreshold

Added in [API level 36.1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setRssiThreshold(rssiThreshold: Int): ScanSettings.Builder
```

Sets the RSSI threshold. When filtering by RSSI threshold, an advertisement will pass the filter only if its RSSI value is greater than or equal to the specified threshold.

| Parameters ||
|---|---|
| `rssiThreshold` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the high threshold of RSSI value. The valid range is \[-127, 126\]. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#` | this builder. This value cannot be `null`. |

### setScanMode

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setScanMode(scanMode: Int): ScanSettings.Builder!
```

Set scan mode for Bluetooth LE scan.

| Parameters ||
|---|---|
| `scanMode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The scan mode can be one of `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER:kotlin.Int`, `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED:kotlin.Int` or `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY:kotlin.Int`. |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | If the `scanMode` is invalid. |

### setScanType

Added in [API level 36.1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setScanType(scanType: Int): ScanSettings.Builder
```

Sets the scan type. Either `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_ACTIVE:kotlin.Int` or `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_PASSIVE:kotlin.Int` can be set. The default value is `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_ACTIVE:kotlin.Int`.

| Parameters ||
|---|---|
| `scanType` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): Either `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_ACTIVE:kotlin.Int` or `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_PASSIVE:kotlin.Int`. If scan type is `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_PASSIVE:kotlin.Int`, scan results are delivered immediately upon receiving an advertising report, without waiting for scan responses. Value is one of the following: - `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_UNKNOWN:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_PASSIVE:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings#SCAN_TYPE_ACTIVE:kotlin.Int` |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanSettings.Builder#` | This value cannot be `null`. |

| Exceptions ||
|---|---|
| `java.lang.IllegalArgumentException` | if invalid scan type is given. |