# AdvertiseData.Builder

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

# Builder

*** ** * ** ***

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

```
class Builder
```

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

Builder for[AdvertiseData](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData).

## Summary

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

|                                                                                                                                                                                                                                                                        Public methods                                                                                                                                                                                                                                                                        ||
|----------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#)! | [addManufacturerData](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#addManufacturerData(kotlin.Int,%20kotlin.ByteArray))`(`manufacturerId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `manufacturerSpecificData:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!`)` Add manufacturer specific data.         |
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#)! | [addServiceData](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#addServiceData(android.os.ParcelUuid,%20kotlin.ByteArray))`(`serviceDataUuid:` `[ParcelUuid](https://developer.android.com/reference/kotlin/android/os/ParcelUuid.html#)!`, `serviceData:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!`)` Add service data to advertise data. |
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#)  | [addServiceSolicitationUuid](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#addServiceSolicitationUuid(android.os.ParcelUuid))`(`serviceSolicitationUuid:` `[ParcelUuid](https://developer.android.com/reference/kotlin/android/os/ParcelUuid.html#)`)` Add a service solicitation UUID to advertise data.                                                                                  |
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#)! | [addServiceUuid](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#addServiceUuid(android.os.ParcelUuid))`(`serviceUuid:` `[ParcelUuid](https://developer.android.com/reference/kotlin/android/os/ParcelUuid.html#)!`)` Add a service UUID to advertise data.                                                                                                                                  |
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#)  | [addTransportDiscoveryData](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#addTransportDiscoveryData(android.bluetooth.le.TransportDiscoveryData))`(`transportDiscoveryData:` `[TransportDiscoveryData](https://developer.android.com/reference/kotlin/android/bluetooth/le/TransportDiscoveryData)`)` Add Transport Discovery Data to advertise data.                                      |
| [AdvertiseData](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData)!                  | [build](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#build())`()` Build the[AdvertiseData](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData).                                                                                                                                                                                                            |
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#)! | [setIncludeDeviceName](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#setIncludeDeviceName(kotlin.Boolean))`(`includeDeviceName:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Set whether the device name should be included in advertise packet.                                                                                                |
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#)! | [setIncludeTxPowerLevel](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#setIncludeTxPowerLevel(kotlin.Boolean))`(`includeTxPowerLevel:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Whether the transmission power level should be included in the advertise packet.                                                                             |

## Public constructors

### Builder

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

```
Builder()
```

## Public methods

### addManufacturerData

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

```
fun addManufacturerData(
    manufacturerId: Int, 
    manufacturerSpecificData: ByteArray!
): AdvertiseData.Builder!
```

Add manufacturer specific data.

Please refer to the Bluetooth Assigned Numbers document provided by the[Bluetooth SIG](https://www.bluetooth.org)for a list of existing company identifiers.

|                                                                    Parameters                                                                     ||
|----------------------------|-----------------------------------------------------------------------------------------------------------------------|
| `manufacturerId`           | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Manufacturer ID assigned by Bluetooth SIG. |
| `manufacturerSpecificData` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!:Manufacturer specific data   |

|                                                  Exceptions                                                  ||
|--------------------------------------|------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | If the`manufacturerId`is negative or`manufacturerSpecificData`is null. |

### addServiceData

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

```
fun addServiceData(
    serviceDataUuid: ParcelUuid!, 
    serviceData: ByteArray!
): AdvertiseData.Builder!
```

Add service data to advertise data.

|                                                                             Parameters                                                                              ||
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| `serviceDataUuid` | [ParcelUuid](https://developer.android.com/reference/kotlin/android/os/ParcelUuid.html#)!:16-bit UUID of the service the data is associated with |
| `serviceData`     | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!:Service data                                            |

|                                      Exceptions                                       ||
|--------------------------------------|-------------------------------------------------|
| `java.lang.IllegalArgumentException` | If the`serviceDataUuid`or`serviceData`is empty. |

### addServiceSolicitationUuid

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

```
fun addServiceSolicitationUuid(serviceSolicitationUuid: ParcelUuid): AdvertiseData.Builder
```

Add a service solicitation UUID to advertise data.

|                                                                                          Parameters                                                                                           ||
|---------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `serviceSolicitationUuid` | [ParcelUuid](https://developer.android.com/reference/kotlin/android/os/ParcelUuid.html#):A service solicitation UUID to be advertised. This value cannot be`null`. |

|                                                                      Return                                                                      ||
|---------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#) | This value cannot be`null`. |

|                                  Exceptions                                   ||
|--------------------------------------|-----------------------------------------|
| `java.lang.IllegalArgumentException` | If the`serviceSolicitationUuid`is null. |

### addServiceUuid

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

```
fun addServiceUuid(serviceUuid: ParcelUuid!): AdvertiseData.Builder!
```

Add a service UUID to advertise data.

|                                                                Parameters                                                                 ||
|---------------|----------------------------------------------------------------------------------------------------------------------------|
| `serviceUuid` | [ParcelUuid](https://developer.android.com/reference/kotlin/android/os/ParcelUuid.html#)!:A service UUID to be advertised. |

|                            Exceptions                             ||
|--------------------------------------|-----------------------------|
| `java.lang.IllegalArgumentException` | If the`serviceUuid`is null. |

### addTransportDiscoveryData

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

```
fun addTransportDiscoveryData(transportDiscoveryData: TransportDiscoveryData): AdvertiseData.Builder
```

Add Transport Discovery Data to advertise data.

|                                                                                                                                                 Parameters                                                                                                                                                  ||
|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `transportDiscoveryData` | [TransportDiscoveryData](https://developer.android.com/reference/kotlin/android/bluetooth/le/TransportDiscoveryData):Transport Discovery Data, consisting of one or more Transport Blocks. Transport Discovery Data AD Type Code is already included. This value cannot be`null`. |

|                                                                      Return                                                                      ||
|---------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [AdvertiseData.Builder](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData.Builder#) | This value cannot be`null`. |

|                                  Exceptions                                  ||
|--------------------------------------|----------------------------------------|
| `java.lang.IllegalArgumentException` | If the`transportDiscoveryData`is empty |

### build

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

```
fun build(): AdvertiseData!
```

Build the[AdvertiseData](https://developer.android.com/reference/kotlin/android/bluetooth/le/AdvertiseData).  

### setIncludeDeviceName

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

```
fun setIncludeDeviceName(includeDeviceName: Boolean): AdvertiseData.Builder!
```

Set whether the device name should be included in advertise packet.  

### setIncludeTxPowerLevel

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

```
fun setIncludeTxPowerLevel(includeTxPowerLevel: Boolean): AdvertiseData.Builder!
```

Whether the transmission power level should be included in the advertise packet. Tx power level field takes 3 bytes in advertise packet.