# BluetoothLeDeviceFilter.Builder

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

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/companion/BluetoothLeDeviceFilter.Builder "View this page in Java")  

```
class Builder
```

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

Builder for[BluetoothLeDeviceFilter](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter)

## Summary

|                                                         Public constructors                                                         ||
|----------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#Builder())`()` <br /> |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ||
|---------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [BluetoothLeDeviceFilter](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter)                   | [build](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#build())`()` <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#)! | [setNamePattern](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#setNamePattern(java.util.regex.Pattern))`(`regex:` `[Pattern](https://developer.android.com/reference/kotlin/java/util/regex/Pattern.html#)?`)` <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#)  | [setRawDataFilter](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#setRawDataFilter(kotlin.ByteArray,%20kotlin.ByteArray))`(`rawDataFilter:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`, `rawDataFilterMask:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)?`)` Filter devices by raw advertisement data, as obtained by[ScanRecord.getBytes](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanRecord.html#getBytes())                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#)  | [setRenameFromBytes](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#setRenameFromBytes(kotlin.String,%20kotlin.String,%20kotlin.Int,%20kotlin.Int,%20java.nio.ByteOrder))`(`prefix:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `suffix:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `bytesFrom:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `bytesLength:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `byteOrder:` `[ByteOrder](https://developer.android.com/reference/kotlin/java/nio/ByteOrder.html#)!`)` Rename the devices shown in the list, using specific bytes from the raw advertisement data ([ScanRecord.getBytes](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanRecord.html#getBytes())) in hexadecimal format, as well as a custom prefix/suffix around them Note that the prefix length is limited to[getRenamePrefixLengthLimit](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter#getRenamePrefixLengthLimit())characters to ensure that there's enough space to display the byte data The range of bytes to be displayed cannot be empty |
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#)  | [setRenameFromName](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#setRenameFromName(kotlin.String,%20kotlin.String,%20kotlin.Int,%20kotlin.Int))`(`prefix:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `suffix:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `nameFrom:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `nameLength:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Rename the devices shown in the list, using specific characters from the advertised name, as well as a custom prefix/suffix around them Note that the prefix length is limited to[getRenamePrefixLengthLimit](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter#getRenamePrefixLengthLimit())characters to ensure that there's enough space to display the byte data The range of name characters to be displayed cannot be empty                                                                                                                                                                                                                                                                       |
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#)  | [setScanFilter](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#setScanFilter(android.bluetooth.le.ScanFilter))`(`scanFilter:` `[ScanFilter](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanFilter.html#)?`)` <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

## Public constructors

### Builder

```
Builder()
```

## Public methods

### build

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

```
fun build(): BluetoothLeDeviceFilter
```

|                                                                      Return                                                                      ||
|---------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [BluetoothLeDeviceFilter](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter) | This value cannot be`null`. |

### setNamePattern

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

```
fun setNamePattern(regex: Pattern?): BluetoothLeDeviceFilter.Builder!
```

|                                                                                                                                                   Parameters                                                                                                                                                   ||
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `regex` | [Pattern](https://developer.android.com/reference/kotlin/java/util/regex/Pattern.html#)?:if set, only devices with[name](https://developer.android.com/reference/kotlin/android/bluetooth/BluetoothDevice.html#getName())matching the given regular expression will be shown This value may be`null`. |

|                                                                          Return                                                                          ||
|---------------------------------------------------------------------------------------------------------------------------------------|-------------------|
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#)! | self for chaining |

### setRawDataFilter

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

```
fun setRawDataFilter(
    rawDataFilter: ByteArray, 
    rawDataFilterMask: ByteArray?
): BluetoothLeDeviceFilter.Builder
```

Filter devices by raw advertisement data, as obtained by[ScanRecord.getBytes](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanRecord.html#getBytes())

|                                                                                           Parameters                                                                                           ||
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `rawDataFilter`     | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html):bit values that have to match against advertized data This value cannot be`null`. |
| `rawDataFilterMask` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)?:bits that have to be matched This value may be`null`.                            |

|                                                                                       Return                                                                                        ||
|--------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#) | self for chaining This value cannot be`null`. |

### setRenameFromBytes

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

```
fun setRenameFromBytes(
    prefix: String, 
    suffix: String, 
    bytesFrom: Int, 
    bytesLength: Int, 
    byteOrder: ByteOrder!
): BluetoothLeDeviceFilter.Builder
```

Rename the devices shown in the list, using specific bytes from the raw advertisement data ([ScanRecord.getBytes](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanRecord.html#getBytes())) in hexadecimal format, as well as a custom prefix/suffix around them Note that the prefix length is limited to[getRenamePrefixLengthLimit](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter#getRenamePrefixLengthLimit())characters to ensure that there's enough space to display the byte data The range of bytes to be displayed cannot be empty

|                                                                                                                 Parameters                                                                                                                 ||
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `prefix`      | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):to be displayed before the byte data This value cannot be`null`.                                                                           |
| `suffix`      | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):to be displayed after the byte data This value cannot be`null`.                                                                            |
| `bytesFrom`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the start byte index to be displayed (inclusive)                                                                                                 |
| `bytesLength` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the number of bytes to be displayed from the given index                                                                                         |
| `byteOrder`   | [ByteOrder](https://developer.android.com/reference/kotlin/java/nio/ByteOrder.html#)!:whether the given range of bytes is big endian (will be displayed in same order) or little endian (will be flipped before displaying) |

|                                                                                       Return                                                                                        ||
|--------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#) | self for chaining This value cannot be`null`. |

### setRenameFromName

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

```
fun setRenameFromName(
    prefix: String, 
    suffix: String, 
    nameFrom: Int, 
    nameLength: Int
): BluetoothLeDeviceFilter.Builder
```

Rename the devices shown in the list, using specific characters from the advertised name, as well as a custom prefix/suffix around them Note that the prefix length is limited to[getRenamePrefixLengthLimit](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter#getRenamePrefixLengthLimit())characters to ensure that there's enough space to display the byte data The range of name characters to be displayed cannot be empty

|                                                                           Parameters                                                                            ||
|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `prefix`     | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):to be displayed before the byte data This value cannot be`null`. |
| `suffix`     | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):to be displayed after the byte data This value cannot be`null`.  |
| `nameFrom`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the start name character index to be displayed (inclusive)             |
| `nameLength` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the number of characters to be displayed from the given index          |

|                                                                                       Return                                                                                        ||
|--------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#) | self for chaining This value cannot be`null`. |

### setScanFilter

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

```
fun setScanFilter(scanFilter: ScanFilter?): BluetoothLeDeviceFilter.Builder
```

|                                                                                                                             Parameters                                                                                                                             ||
|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `scanFilter` | [ScanFilter](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanFilter.html#)?:a[ScanFilter](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanFilter.html#)to filter devices by This value may be`null`. |

|                                                                                       Return                                                                                        ||
|--------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [BluetoothLeDeviceFilter.Builder](https://developer.android.com/reference/kotlin/android/companion/BluetoothLeDeviceFilter.Builder#) | self for chaining This value cannot be`null`. |

**See Also**

- [android.bluetooth.le.ScanFilter](https://developer.android.com/reference/kotlin/android/bluetooth/le/ScanFilter.html#)