# AssociationRequest.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/AssociationRequest.Builder "View this page in Java")  

```
class Builder
```

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

A builder for[AssociationRequest](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest)

## Summary

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

|                                                                                                                                                                                                                                                                                                                                                            Public methods                                                                                                                                                                                                                                                                                                                                                            ||
|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [AssociationRequest.Builder](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#) | [addDeviceFilter](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#addDeviceFilter(android.companion.DeviceFilter))`(`deviceFilter:` `[DeviceFilter](https://developer.android.com/reference/kotlin/android/companion/DeviceFilter)<*>?`)` <br />                                                                                                                                                                                                                                                                                                             |
| [AssociationRequest](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest)                  | [build](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#build())`()` <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [AssociationRequest.Builder](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#) | [setDeviceIcon](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#setDeviceIcon(android.graphics.drawable.Icon))`(`deviceIcon:` `[Icon](https://developer.android.com/reference/kotlin/android/graphics/drawable/Icon.html#)`)` Set the device icon for the self-managed device and to display the icon in the self-managed association dialog.                                                                                                                                                                                                                |
| [AssociationRequest.Builder](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#) | [setDeviceProfile](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#setDeviceProfile(kotlin.String))`(`deviceProfile:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` If set, association will be requested as a corresponding kind of device                                                                                                                                                                                                                                                                           |
| [AssociationRequest.Builder](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#) | [setDisplayName](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#setDisplayName(kotlin.CharSequence))`(`displayName:` `[CharSequence](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/index.html)`)` Adds a display name.                                                                                                                                                                                                                                                                                                                 |
| [AssociationRequest.Builder](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#) | [setForceConfirmation](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#setForceConfirmation(kotlin.Boolean))`(`forceConfirmation:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Indicates whether the application requires the[CompanionDeviceManager](https://developer.android.com/reference/kotlin/android/companion/CompanionDeviceManager)service to collect an explicit confirmation from the user before creating an association, even if such confirmation is not required from the service's perspective. |
| [AssociationRequest.Builder](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#) | [setSelfManaged](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#setSelfManaged(kotlin.Boolean))`(`selfManaged:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Indicate whether the association would be managed by the companion application.                                                                                                                                                                                                                                                                      |
| [AssociationRequest.Builder](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#) | [setSingleDevice](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#setSingleDevice(kotlin.Boolean))`(`singleDevice:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Whether only a single device should match the provided filter.                                                                                                                                                                                                                                                                                    |

## Public constructors

### Builder

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

```
Builder()
```

## Public methods

### addDeviceFilter

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

```
fun addDeviceFilter(deviceFilter: DeviceFilter<*>?): AssociationRequest.Builder
```

|                                                                                                       Parameters                                                                                                       ||
|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `deviceFilter` | [DeviceFilter](https://developer.android.com/reference/kotlin/android/companion/DeviceFilter)\<\*\>?:if set, only devices matching the given filter will be shown to the user This value may be`null`. |

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

### build

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

```
fun build(): AssociationRequest
```

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

### setDeviceIcon

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

```
fun setDeviceIcon(deviceIcon: Icon): AssociationRequest.Builder
```

Set the device icon for the self-managed device and to display the icon in the self-managed association dialog.

The given device icon will be resized to 24dp x 24dp.  
Requires[android.Manifest.permission#REQUEST_COMPANION_SELF_MANAGED](https://developer.android.com/reference/kotlin/android/Manifest.permission.html#REQUEST_COMPANION_SELF_MANAGED:kotlin.String)

|                                                              Parameters                                                               ||
|--------------|-------------------------------------------------------------------------------------------------------------------------|
| `deviceIcon` | [Icon](https://developer.android.com/reference/kotlin/android/graphics/drawable/Icon.html#):This value cannot be`null`. |

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

|                                                                                                                                                              Exceptions                                                                                                                                                               ||
|--------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if the icon is[Icon.TYPE_URI](https://developer.android.com/reference/kotlin/android/graphics/drawable/Icon.html#TYPE_URI:kotlin.Int)or[Icon.TYPE_URI_ADAPTIVE_BITMAP](https://developer.android.com/reference/kotlin/android/graphics/drawable/Icon.html#TYPE_URI_ADAPTIVE_BITMAP:kotlin.Int). |

**See Also**

- [#setSelfManaged(boolean)](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#setSelfManaged(kotlin.Boolean))  

### setDeviceProfile

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

```
fun setDeviceProfile(deviceProfile: String): AssociationRequest.Builder
```

If set, association will be requested as a corresponding kind of device

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ||
|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `deviceProfile` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):This value cannot be`null`. Value is[android.companion.AssociationRequest#DEVICE_PROFILE_WATCH](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest#DEVICE_PROFILE_WATCH:kotlin.String),[android.companion.AssociationRequest#DEVICE_PROFILE_COMPUTER](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest#DEVICE_PROFILE_COMPUTER:kotlin.String),[android.companion.AssociationRequest#DEVICE_PROFILE_AUTOMOTIVE_PROJECTION](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest#DEVICE_PROFILE_AUTOMOTIVE_PROJECTION:kotlin.String),[android.companion.AssociationRequest#DEVICE_PROFILE_APP_STREAMING](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest#DEVICE_PROFILE_APP_STREAMING:kotlin.String),[android.companion.AssociationRequest#DEVICE_PROFILE_GLASSES](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest#DEVICE_PROFILE_GLASSES:kotlin.String),[android.companion.AssociationRequest#DEVICE_PROFILE_NEARBY_DEVICE_STREAMING](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest#DEVICE_PROFILE_NEARBY_DEVICE_STREAMING:kotlin.String), or android.companion.AssociationRequest.DEVICE_PROFILE_WEARABLE_SENSING |

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

### setDisplayName

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

```
fun setDisplayName(displayName: CharSequence): AssociationRequest.Builder
```

Adds a display name. Generally[AssociationRequest](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest)s are not required to provide a display name, except for request for creating "self-managed" associations, which MUST provide a display name.

|                                                                                Parameters                                                                                ||
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `displayName` | [CharSequence](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/index.html):the display name of the device. This value cannot be`null`. |

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

### setForceConfirmation

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

```
fun setForceConfirmation(forceConfirmation: Boolean): AssociationRequest.Builder
```

Indicates whether the application requires the[CompanionDeviceManager](https://developer.android.com/reference/kotlin/android/companion/CompanionDeviceManager)service to collect an explicit confirmation from the user before creating an association, even if such confirmation is not required from the service's perspective.  
Requires[android.Manifest.permission#REQUEST_COMPANION_SELF_MANAGED](https://developer.android.com/reference/kotlin/android/Manifest.permission.html#REQUEST_COMPANION_SELF_MANAGED:kotlin.String)

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

### setSelfManaged

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

```
fun setSelfManaged(selfManaged: Boolean): AssociationRequest.Builder
```

Indicate whether the association would be managed by the companion application. Requests for creating "self-managed" association MUST provide a Display name.  
Requires[android.Manifest.permission#REQUEST_COMPANION_SELF_MANAGED](https://developer.android.com/reference/kotlin/android/Manifest.permission.html#REQUEST_COMPANION_SELF_MANAGED:kotlin.String)

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

**See Also**

- [#setDisplayName(CharSequence)](https://developer.android.com/reference/kotlin/android/companion/AssociationRequest.Builder#setDisplayName(kotlin.CharSequence))  

### setSingleDevice

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

```
fun setSingleDevice(singleDevice: Boolean): AssociationRequest.Builder
```

Whether only a single device should match the provided filter. When scanning for a single device with a specific[BluetoothDeviceFilter](https://developer.android.com/reference/kotlin/android/companion/BluetoothDeviceFilter)mac address, bonded devices are also searched among. This allows to obtain the necessary app privileges even if the device is already paired.

|                                                                                         Parameters                                                                                          ||
|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `singleDevice` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):if true, scanning for a device will stop as soon as at least one fitting device is found |

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