# TrafficDescriptor.Builder

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

# Builder

*** ** * ** ***

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

```
class Builder
```

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

Provides a convenient way to set the fields of a[TrafficDescriptor](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor)when creating a new instance.

The example below shows how you might create a new`TrafficDescriptor`:  

```kotlin
<code>
 
  TrafficDescriptor response = new TrafficDescriptor.Builder()
      .setDnn("")
      .build();
  </code>
```

## Summary

|                                                                     Public constructors                                                                      ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor.Builder#Builder())`()` Default constructor for Builder. |

|                                                                                                                                                                                                                 Public methods                                                                                                                                                                                                                 ||
|-------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [TrafficDescriptor](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor)                  | [build](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor.Builder#build())`()` Build the[TrafficDescriptor](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor).                                                                     |
| [TrafficDescriptor.Builder](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor.Builder#) | [setDataNetworkName](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor.Builder#setDataNetworkName(kotlin.String))`(`dnn:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Set the Data Network Name(DNN).                            |
| [TrafficDescriptor.Builder](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor.Builder#) | [setOsAppId](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor.Builder#setOsAppId(kotlin.ByteArray))`(`osAppId:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`)` Set the OS App ID (including OS Id as defined in the specs). |

## Public constructors

### Builder

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

```
Builder()
```

Default constructor for Builder.

## Public methods

### build

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

```
fun build(): TrafficDescriptor
```

Build the[TrafficDescriptor](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor).

|                                                                                                                              Return                                                                                                                              ||
|--------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [TrafficDescriptor](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor) | the[TrafficDescriptor](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor)object. This value cannot be`null`. |

|                              Exceptions                              ||
|--------------------------------------|--------------------------------|
| `java.lang.IllegalArgumentException` | if DNN and OS App ID are null. |

### setDataNetworkName

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

```
fun setDataNetworkName(dnn: String): TrafficDescriptor.Builder
```

Set the Data Network Name(DNN).

|                                                     Parameters                                                      ||
|-------|--------------------------------------------------------------------------------------------------------------|
| `dnn` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):This value cannot be`null`. |

|                                                                                            Return                                                                                            ||
|-------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
| [TrafficDescriptor.Builder](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor.Builder#) | The same instance of the builder. This value cannot be`null`. |

### setOsAppId

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

```
fun setOsAppId(osAppId: ByteArray): TrafficDescriptor.Builder
```

Set the OS App ID (including OS Id as defined in the specs).

|                                                           Parameters                                                           ||
|-----------|---------------------------------------------------------------------------------------------------------------------|
| `osAppId` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html):This value cannot be`null`. |

|                                                                                            Return                                                                                            ||
|-------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
| [TrafficDescriptor.Builder](https://developer.android.com/reference/kotlin/android/telephony/data/TrafficDescriptor.Builder#) | The same instance of the builder. This value cannot be`null`. |