Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/companion/CompanionDeviceManager#nestedclasses) \| [Constants](https://developer.android.com/reference/android/companion/CompanionDeviceManager#constants) \| [Methods](https://developer.android.com/reference/android/companion/CompanionDeviceManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/companion/CompanionDeviceManager#inhmethods)

# CompanionDeviceManager

*** ** * ** ***


`
public

final

class
CompanionDeviceManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.companion.CompanionDeviceManager |

<br />

*** ** * ** ***

Public interfaces for managing companion devices.

The interfaces in this class allow companion apps to
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.Callback)` discover and request device profiles}
for companion devices, `https://developer.android.com/reference/android/companion/CompanionDeviceManager#startObservingDevicePresence(java.lang.String)`, `https://developer.android.com/reference/android/companion/CompanionDeviceManager#startSystemDataTransfer(int,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>)` via `https://developer.android.com/reference/android/companion/CompanionDeviceManager#attachSystemDataTransport(int,%20java.io.InputStream,%20java.io.OutputStream)` and more.

### Developer Guides

For more information about managing companion devices, read the [Companion Device Pairing](https://developer.android.com/guide/topics/connectivity/companion-device-pairing)
developer guide.
.   
Requires the `https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` feature which can be detected using `https://developer.android.com/reference/android/content/pm/PackageManager#hasSystemFeature(java.lang.String)`.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback` Callback for applications to receive updates about and the outcome of `https://developer.android.com/reference/android/companion/AssociationRequest` issued via `associate()` call. |
| ` class` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager.TrustPairingCallback` Callback for applications to receive updates about and the outcome of `https://developer.android.com/reference/android/companion/CompanionDeviceManager#requestDeviceTrustPairing(int,%20android.companion.OutOfBandPairingRequest,%20int[],%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.TrustPairingCallback)` |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#ERROR_TRUST_OUT_OF_BAND_PAIRING_FAILED` The out of band pairing failed. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#ERROR_TRUST_PAIRING_ASSOCIATION_DOES_NOT_EXIST` The association does not exist. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#ERROR_TRUST_PAIRING_CANCELED` The trust pairing dialog was cancelled by the user or implicitly. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#ERROR_TRUST_PAIRING_FAILED_TO_CREATE_PAIRING_DIALOG` Failed to create or send pairing dialog for trust pairing. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#ERROR_TRUST_PAIRING_PIN_CODE_NOT_MATCHING` The PIN code confirmed by the user did not match. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#ERROR_TRUST_PAIRING_TRANSPORT_NOT_ATTACHED` The transport was not attached for trust pairing. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#ERROR_TRUST_RESUMPTION_FAILED` The trust resumption failed. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#ERROR_TRUST_UNKNOWN` Unknown error for trust pairing. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#EXTRA_ASSOCIATION` Extra field name for the `https://developer.android.com/reference/android/companion/AssociationInfo` object, included into `https://developer.android.com/reference/android/content/Intent` which application receive in `https://developer.android.com/reference/android/app/Activity#onActivityResult(int,%20int,%20android.content.Intent)` after the application's `https://developer.android.com/reference/android/companion/AssociationRequest` was successfully processed and an association was created. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#EXTRA_DEVICE` *This constant was deprecated in API level 33. use `https://developer.android.com/reference/android/companion/AssociationInfo#getAssociatedDevice()` instead.* |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_AIRPLANE_MODE` Used by `https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)`}. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_CALL_METADATA` Used by `https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)`}. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_TASK_CONTINUITY` Used by `https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)`}. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_UNIVERSAL_MODES` Used by `https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)`}. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_CANCELED` The result code to propagate back to the user activity, indicates if the association dialog is implicitly cancelled. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_DISCOVERY_TIMEOUT` The result code to propagate back to the user activity, indicates the association dialog is dismissed if there's no device found after 20 seconds. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_INTERNAL_ERROR` The result code to propagate back to the user activity, indicates the internal error in CompanionDeviceManager. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_OK` The result code to propagate back to the user activity, indicates the association is created successfully. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_SECURITY_ERROR` The result code to propagate back to the user activity and `https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onFailure(int,%20java.lang.CharSequence)`, indicates app is not allow to create the association due to the security issue. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_USER_REJECTED` The result code to propagate back to the user activity, indicates the association dialog is explicitly declined by the users. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#TRUST_TYPE_CROSS_DEVICE_AUTHENTICATION` Trust type for platform-level cross-device authentication. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#TRUST_TYPE_PROACTIVE_ASSISTANCE` Trust type for proactive assistance. |
| `int` | `https://developer.android.com/reference/android/companion/CompanionDeviceManager#TRUST_TYPE_SCREEN_AUTOMATION` Trust type for screen automation. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.Callback)(https://developer.android.com/reference/android/companion/AssociationRequest request, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback callback) ` Request to associate this app with a companion device. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20android.companion.CompanionDeviceManager.Callback,%20android.os.Handler)(https://developer.android.com/reference/android/companion/AssociationRequest request, https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback callback, https://developer.android.com/reference/android/os/Handler handler) ` Request to associate this app with a companion device. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#attachSystemDataTransport(int,%20java.io.InputStream,%20java.io.OutputStream)(int associationId, https://developer.android.com/reference/java/io/InputStream in, https://developer.android.com/reference/java/io/OutputStream out) ` Attach a bidirectional communication stream to be used as a transport channel for transporting system data between associated devices. |
| ` https://developer.android.com/reference/android/content/IntentSender` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#buildAssociationCancellationIntent()() ` Cancel the current association activity. |
| ` https://developer.android.com/reference/android/content/IntentSender` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#buildPermissionTransferUserConsentIntent(int)(int associationId) ` Build a permission sync user consent dialog. |
| ` https://developer.android.com/reference/android/companion/DeviceId` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#createAndSetDeviceId(int,%20android.companion.DeviceId)(int associationId, https://developer.android.com/reference/android/companion/DeviceId deviceId) ` Returns a new `https://developer.android.com/reference/android/companion/DeviceId` which can be passed to device manufacturers' apps, allowing them to fetch `https://developer.android.com/reference/android/companion/AssociationInfo` or observe device presence for this associated device. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#detachSystemDataTransport(int)(int associationId) ` Detach the transport channel that's previously attached for the associated device. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#disableSystemDataSyncForTypes(int,%20int)(int associationId, int flags) ` <br /> Disable system data sync for an associated device. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#disassociate(int)(int associationId) ` Remove an association. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#disassociate(java.lang.String)(https://developer.android.com/reference/java/lang/String deviceMacAddress) ` *This method was deprecated in API level 33. use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#disassociate(int)`* |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)(int associationId, int flags) ` <br /> Enable system data sync for an associated device. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#getAssociations()() ` *This method was deprecated in API level 33. use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#getMyAssociations()`* |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/companion/AssociationInfo>` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#getMyAssociations()() ` <br /> Calling this API requires a uses-feature `https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest <br /> |
| ` boolean` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#hasNotificationAccess(android.content.ComponentName)(https://developer.android.com/reference/android/content/ComponentName component) ` *This method was deprecated in API level 33. Use `https://developer.android.com/reference/android/app/NotificationManager#isNotificationListenerAccessGranted(android.content.ComponentName)` instead.* |
| ` boolean` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#isPermissionTransferUserConsented(int)(int associationId) ` Return the current state of consent for permission transfer for the association. |
| ` boolean` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#isSystemDataTransportAttached(int)(int associationId) ` Checks if a transport is currently attached for a given association id. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#notifyActionResult(int,%20android.companion.ActionResult)(int associationId, https://developer.android.com/reference/android/companion/ActionResult result) ` Allows a companion app to report the result of an action that was requested by the system. |
| ` boolean` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#removeBond(int)(int associationId) ` Remove bonding between this device and an associated companion device. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#requestDeviceTrustPairing(int,%20android.companion.OutOfBandPairingRequest,%20int[],%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.TrustPairingCallback)(int associationId, https://developer.android.com/reference/android/companion/OutOfBandPairingRequest requestOobPairing, int[] trustTypes, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/companion/CompanionDeviceManager.TrustPairingCallback callback) ` Request the system to initiate a trusted pairing process for the given association. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#requestNotificationAccess(android.content.ComponentName)(https://developer.android.com/reference/android/content/ComponentName component) ` Request notification access for the given component. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#setDeviceId(int,%20android.companion.DeviceId)(int associationId, https://developer.android.com/reference/android/companion/DeviceId deviceId) ` *This method was deprecated in API level 36.1. use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#createAndSetDeviceId(int,%20android.companion.DeviceId)` instead.* |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#startObservingDevicePresence(android.companion.ObservingDevicePresenceRequest)(https://developer.android.com/reference/android/companion/ObservingDevicePresenceRequest request) ` Register to receive callbacks whenever the associated device's presence changes. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#startObservingDevicePresence(java.lang.String)(https://developer.android.com/reference/java/lang/String deviceAddress) ` *This method was deprecated in API level 36. use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#startObservingDevicePresence(android.companion.ObservingDevicePresenceRequest)` instead.* |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#startSystemDataTransfer(int,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>)(int associationId, https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/android/companion/CompanionException> result) ` Start system data transfer which has been previously approved by the user. |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#stopObservingDevicePresence(java.lang.String)(https://developer.android.com/reference/java/lang/String deviceAddress) ` *This method was deprecated in API level 36. use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#stopObservingDevicePresence(android.companion.ObservingDevicePresenceRequest)` instead.* |
| ` void` | ` https://developer.android.com/reference/android/companion/CompanionDeviceManager#stopObservingDevicePresence(android.companion.ObservingDevicePresenceRequest)(https://developer.android.com/reference/android/companion/ObservingDevicePresenceRequest request) ` Unregister for receiving callbacks whenever the associated device comes in and out of range. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


## Constants

### ERROR_TRUST_OUT_OF_BAND_PAIRING_FAILED

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int ERROR_TRUST_OUT_OF_BAND_PAIRING_FAILED
```

The out of band pairing failed.

<br />

Constant Value:

7
(0x00000007)


### ERROR_TRUST_PAIRING_ASSOCIATION_DOES_NOT_EXIST

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int ERROR_TRUST_PAIRING_ASSOCIATION_DOES_NOT_EXIST
```

The association does not exist.

<br />

Constant Value:

5
(0x00000005)


### ERROR_TRUST_PAIRING_CANCELED

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int ERROR_TRUST_PAIRING_CANCELED
```

The trust pairing dialog was cancelled by the user or implicitly.

<br />

Constant Value:

2
(0x00000002)


### ERROR_TRUST_PAIRING_FAILED_TO_CREATE_PAIRING_DIALOG

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int ERROR_TRUST_PAIRING_FAILED_TO_CREATE_PAIRING_DIALOG
```

Failed to create or send pairing dialog for trust pairing.

<br />

Constant Value:

3
(0x00000003)


### ERROR_TRUST_PAIRING_PIN_CODE_NOT_MATCHING

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int ERROR_TRUST_PAIRING_PIN_CODE_NOT_MATCHING
```

The PIN code confirmed by the user did not match.

<br />

Constant Value:

4
(0x00000004)


### ERROR_TRUST_PAIRING_TRANSPORT_NOT_ATTACHED

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int ERROR_TRUST_PAIRING_TRANSPORT_NOT_ATTACHED
```

The transport was not attached for trust pairing.

<br />

Constant Value:

1
(0x00000001)


### ERROR_TRUST_RESUMPTION_FAILED

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int ERROR_TRUST_RESUMPTION_FAILED
```

The trust resumption failed.

This error is returned when the system fails to resume a previous trust relationship.
You can try to re-attach the transport to resume the trust relationship.

If re-attaching fails, you can try to re-pair the devices.

<br />

Constant Value:

6
(0x00000006)


### ERROR_TRUST_UNKNOWN

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int ERROR_TRUST_UNKNOWN
```

Unknown error for trust pairing.

<br />

Constant Value:

0
(0x00000000)


### EXTRA_ASSOCIATION

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

```
public static final String EXTRA_ASSOCIATION
```

Extra field name for the `https://developer.android.com/reference/android/companion/AssociationInfo` object, included into
`https://developer.android.com/reference/android/content/Intent` which application receive in
`https://developer.android.com/reference/android/app/Activity#onActivityResult(int,%20int,%20android.content.Intent)` after the application's
`https://developer.android.com/reference/android/companion/AssociationRequest` was successfully processed and an association was created.

<br />

Constant Value:

"android.companion.extra.ASSOCIATION"


### EXTRA_DEVICE

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

```
public static final String EXTRA_DEVICE
```


**This constant was deprecated
in API level 33.**   

use `https://developer.android.com/reference/android/companion/AssociationInfo#getAssociatedDevice()` instead.

A device, returned in the activity result of the `https://developer.android.com/reference/android/content/IntentSender` received in
`https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onDeviceFound(android.content.IntentSender)`

Type is:

- for classic Bluetooth - `https://developer.android.com/reference/android/bluetooth/BluetoothDevice`
- for Bluetooth LE - `https://developer.android.com/reference/android/bluetooth/le/ScanResult`
- for WiFi - `https://developer.android.com/reference/android/net/wifi/ScanResult`

<br />

<br />

Constant Value:

"android.companion.extra.DEVICE"


### FLAG_AIRPLANE_MODE

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

```
public static final int FLAG_AIRPLANE_MODE
```

Used by `https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)`}.
Synchronize airplane mode state across devices.
Disabled by default.

<br />

Constant Value:

16
(0x00000010)


### FLAG_CALL_METADATA

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

```
public static final int FLAG_CALL_METADATA
```

Used by `https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)`}.
Sync call metadata like muting, ending and silencing a call.
Enabled by default.

<br />

Constant Value:

1
(0x00000001)


### FLAG_TASK_CONTINUITY

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

```
public static final int FLAG_TASK_CONTINUITY
```

Used by `https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)`}.
Synchronize task continuity data like open tasks, and enable this transport for Handoff.
Disabled by default.

<br />

Constant Value:

2
(0x00000002)


### FLAG_UNIVERSAL_MODES

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

```
public static final int FLAG_UNIVERSAL_MODES
```

Used by `https://developer.android.com/reference/android/companion/CompanionDeviceManager#enableSystemDataSyncForTypes(int,%20int)`}.
Synchronize user settings like contextual modes across devices.
Disabled by default.

<br />

Constant Value:

4
(0x00000004)


### RESULT_CANCELED

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

```
public static final int RESULT_CANCELED
```

The result code to propagate back to the user activity, indicates if the association dialog
is implicitly cancelled.
E.g. phone is locked, switch to another app or press outside the dialog.

<br />

Constant Value:

0
(0x00000000)


### RESULT_DISCOVERY_TIMEOUT

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

```
public static final int RESULT_DISCOVERY_TIMEOUT
```

The result code to propagate back to the user activity, indicates the association
dialog is dismissed if there's no device found after 20 seconds.

<br />

Constant Value:

2
(0x00000002)


### RESULT_INTERNAL_ERROR

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

```
public static final int RESULT_INTERNAL_ERROR
```

The result code to propagate back to the user activity, indicates the internal error
in CompanionDeviceManager.

<br />

Constant Value:

3
(0x00000003)


### RESULT_OK

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

```
public static final int RESULT_OK
```

The result code to propagate back to the user activity, indicates the association
is created successfully.

<br />

Constant Value:

-1
(0xffffffff)


### RESULT_SECURITY_ERROR

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

```
public static final int RESULT_SECURITY_ERROR
```

The result code to propagate back to the user activity and
`https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onFailure(int,%20java.lang.CharSequence)`, indicates app is not allow to create the
association due to the security issue.
E.g. There are missing necessary permissions when creating association.

<br />

Constant Value:

4
(0x00000004)


### RESULT_USER_REJECTED

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

```
public static final int RESULT_USER_REJECTED
```

The result code to propagate back to the user activity, indicates the association dialog
is explicitly declined by the users.

<br />

Constant Value:

1
(0x00000001)


### TRUST_TYPE_CROSS_DEVICE_AUTHENTICATION

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int TRUST_TYPE_CROSS_DEVICE_AUTHENTICATION
```

Trust type for platform-level cross-device authentication.

This trust type is used for features where one device can authenticate another, typically
based on proximity. For example, allowing a trusted watch to unlock a companion phone.

When this trust type is requested and granted during Companion Device Manager (CDM) trust
pairing, the platform utilizes the established secure channel to facilitate these
authentication flows.

<br />

**See also:**

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#requestDeviceTrustPairing(int,%20android.companion.OutOfBandPairingRequest,%20int[],%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.TrustPairingCallback)`

Constant Value:

2
(0x00000002)


### TRUST_TYPE_PROACTIVE_ASSISTANCE

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int TRUST_TYPE_PROACTIVE_ASSISTANCE
```

Trust type for proactive assistance. E.g. agents can use your app's screen content to provide
proactive assistance.

<br />

**See also:**

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#requestDeviceTrustPairing(int,%20android.companion.OutOfBandPairingRequest,%20int[],%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.TrustPairingCallback)`

Constant Value:

1
(0x00000001)


### TRUST_TYPE_SCREEN_AUTOMATION

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int TRUST_TYPE_SCREEN_AUTOMATION
```

Trust type for screen automation. E.g. allowing agents to see and interact with the screen
to help you complete tasks even if the screen is off.

<br />

**See also:**

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#requestDeviceTrustPairing(int,%20android.companion.OutOfBandPairingRequest,%20int[],%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.TrustPairingCallback)`

Constant Value:

0
(0x00000000)


## Public methods

### associate

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

```
public void associate (AssociationRequest request, 
                Executor executor, 
                CompanionDeviceManager.Callback callback)
```

Request to associate this app with a companion device.

Note that before creating establishing association the system may need to show UI to
collect user confirmation.

If the app needs to be excluded from battery optimizations (run in the background)
or to have unrestricted data access (use data in the background) it should declare use of
`https://developer.android.com/reference/android/Manifest.permission#REQUEST_COMPANION_RUN_IN_BACKGROUND` and
`https://developer.android.com/reference/android/Manifest.permission#REQUEST_COMPANION_USE_DATA_IN_BACKGROUND` in its
AndroidManifest.xml respectively.
Note that these special capabilities have a negative effect on the device's battery and
user's data usage, therefore you should request them when absolutely necessary.

Application can use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#getMyAssociations()` for retrieving the list of currently
`https://developer.android.com/reference/android/companion/AssociationInfo` objects, that represent their existing associations.
Applications can also use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#disassociate(int)` to remove an association, and are
recommended to do when an association is no longer relevant to avoid unnecessary battery
and/or data drain resulting from special privileges that the association provides

Note that if you use this api to associate with a Bluetooth device, please make sure
to cancel your own Bluetooth discovery before calling this api, otherwise the callback
may fail to return the desired device.

If this API is used to associate with a Bluetooth device, initiating Bluetooth bonding
(e.g. via `https://developer.android.com/reference/android/bluetooth/BluetoothDevice#createBond()`) within 10 minutes of the association being
approved allows the device to skip the Bluetooth pairing confirmation dialog (if its
pairing variant is `https://developer.android.com/`).

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Parameters ||
|---|---|
| `request` | `AssociationRequest`: A request object that describes details of the request. This value cannot be `null`. <br /> |
| `executor` | `Executor`: The executor which will be used to invoke the callback. This value cannot be `null`. <br /> |
| `callback` | `CompanionDeviceManager.Callback`: The callback used to notify application when the association is created. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/companion/AssociationRequest.Builder`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#getMyAssociations()`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#disassociate(int)`
- `https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#cancelDiscovery()`
- `https://developer.android.com/reference/android/bluetooth/BluetoothDevice#createBond()`

### associate

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

```
public void associate (AssociationRequest request, 
                CompanionDeviceManager.Callback callback, 
                Handler handler)
```

Request to associate this app with a companion device.

Note that before creating establishing association the system may need to show UI to
collect user confirmation.

If the app needs to be excluded from battery optimizations (run in the background)
or to have unrestricted data access (use data in the background) it should declare use of
`https://developer.android.com/reference/android/Manifest.permission#REQUEST_COMPANION_RUN_IN_BACKGROUND` and
`https://developer.android.com/reference/android/Manifest.permission#REQUEST_COMPANION_USE_DATA_IN_BACKGROUND` in its
AndroidManifest.xml respectively.
Note that these special capabilities have a negative effect on the device's battery and
user's data usage, therefore you should request them when absolutely necessary.

Application can use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#getMyAssociations()` for retrieving the list of currently
`https://developer.android.com/reference/android/companion/AssociationInfo` objects, that represent their existing associations.
Applications can also use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#disassociate(int)` to remove an association, and are
recommended to do when an association is no longer relevant to avoid unnecessary battery
and/or data drain resulting from special privileges that the association provides

If this API is used to associate with a Bluetooth device, initiating Bluetooth bonding
(e.g. via `https://developer.android.com/reference/android/bluetooth/BluetoothDevice#createBond()`) within 10 minutes of the association being
approved allows the device to skip the Bluetooth pairing confirmation dialog (if its
pairing variant is `https://developer.android.com/`).

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Parameters ||
|---|---|
| `request` | `AssociationRequest`: A request object that describes details of the request. This value cannot be `null`. <br /> |
| `callback` | `CompanionDeviceManager.Callback`: The callback used to notify application when the association is created. This value cannot be `null`. <br /> |
| `handler` | `Handler`: The handler which will be used to invoke the callback. This value may be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/companion/AssociationRequest.Builder`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#getMyAssociations()`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#disassociate(int)`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.Callback)`
- `https://developer.android.com/reference/android/bluetooth/BluetoothDevice#createBond()`

### attachSystemDataTransport

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

```
public void attachSystemDataTransport (int associationId, 
                InputStream in, 
                OutputStream out)
```

Attach a bidirectional communication stream to be used as a transport channel for
transporting system data between associated devices.


Requires `https://developer.android.com/reference/android/Manifest.permission#DELIVER_COMPANION_MESSAGES`

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: id of the associated device. <br /> |
| `in` | `InputStream`: Already connected stream of data incoming from remote associated device. This value cannot be `null`. <br /> |
| `out` | `OutputStream`: Already connected stream of data outgoing to remote associated device. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/companion/DeviceNotAssociatedException` | Thrown if the associationId was not previously associated with this app. |

**See also:**

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#buildPermissionTransferUserConsentIntent(int)`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#startSystemDataTransfer(int,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>)`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#detachSystemDataTransport(int)`

### buildAssociationCancellationIntent

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

```
public IntentSender buildAssociationCancellationIntent ()
```

Cancel the current association activity.

The app should launch the returned `intentSender` by calling
`https://developer.android.com/reference/android/app/Activity#startIntentSenderForResult(android.content.IntentSender,%20int,%20android.content.Intent,%20int,%20int,%20int)` to
cancel the current association activity

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/IntentSender` | An `https://developer.android.com/reference/android/content/IntentSender` that the app should use to launch in order to cancel the current association activity. This value may be `null`. <br /> |

### buildPermissionTransferUserConsentIntent

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

```
public IntentSender buildPermissionTransferUserConsentIntent (int associationId)
```

Build a permission sync user consent dialog.

Only the companion app which owns the association can call this method. Otherwise a null
IntentSender will be returned from this method and an error will be logged.
The app should launch the `https://developer.android.com/reference/android/app/Activity` in the returned `intentSender`
`https://developer.android.com/reference/android/content/IntentSender` by calling
`https://developer.android.com/reference/android/app/Activity#startIntentSenderForResult(android.content.IntentSender,%20int,%20android.content.Intent,%20int,%20int,%20int)`.

The permission transfer doesn't happen immediately after the call or when the user
consents. The app needs to call
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#attachSystemDataTransport(int,%20java.io.InputStream,%20java.io.OutputStream)` to attach a transport
channel and
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#startSystemDataTransfer(int,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>)` to trigger the system data
transfer}.

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: The unique `https://developer.android.com/reference/android/companion/AssociationInfo#getId()` assigned to the association of the companion device recorded by CompanionDeviceManager <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/IntentSender` | An `https://developer.android.com/reference/android/content/IntentSender` that the app should use to launch the UI for the user to confirm the system data transfer request. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/companion/DeviceNotAssociatedException` |   |

**See also:**

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#attachSystemDataTransport(int,%20java.io.InputStream,%20java.io.OutputStream)`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#startSystemDataTransfer(int,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>)`

### createAndSetDeviceId

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public DeviceId createAndSetDeviceId (int associationId, 
                DeviceId deviceId)
```

Returns a new `https://developer.android.com/reference/android/companion/DeviceId` which can be passed to device manufacturers' apps,
allowing them to fetch `https://developer.android.com/reference/android/companion/AssociationInfo` or observe device presence for this
associated device. This method creates a new object and does not mutate any existing
`https://developer.android.com/reference/android/companion/DeviceId`.

The system will generate and assign a new, random 128-bit key to this returned
`https://developer.android.com/reference/android/companion/DeviceId`. Each call to this method generates a new key, any previously associated
key will be obsoleted. Therefore, the returned `https://developer.android.com/reference/android/companion/DeviceId` is the one that contains
the newly assigned key and should be used for subsequent operations.

Calling this method also refreshes the association's
`https://developer.android.com/reference/android/companion/AssociationInfo#getAssociationToken()`.

This device id also helps the system uniquely identify your device for efficient device
management and prevents duplicate entries.

WARNING: Do not pass the returned DeviceId to apps you do not trust.

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: The unique `https://developer.android.com/reference/android/companion/AssociationInfo#getId()` assigned to the Association of the companion device recorded by CompanionDeviceManager. <br /> |
| `deviceId` | `DeviceId`: to be used as device identifier to represent the associated device. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/companion/DeviceId` | This value may be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/companion/AssociationInfo#getDeviceId()`
- `https://developer.android.com/reference/android/companion/AssociationInfo#getAssociationToken()`

### detachSystemDataTransport

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

```
public void detachSystemDataTransport (int associationId)
```

Detach the transport channel that's previously attached for the associated device. The system
will stop transferring any system data when this method is called.


Requires `https://developer.android.com/reference/android/Manifest.permission#DELIVER_COMPANION_MESSAGES`

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: id of the associated device. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/companion/DeviceNotAssociatedException` | Thrown if the associationId was not previously associated with this app. |

**See also:**

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#attachSystemDataTransport(int,%20java.io.InputStream,%20java.io.OutputStream)`

### disableSystemDataSyncForTypes

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

```
public void disableSystemDataSyncForTypes (int associationId, 
                int flags)
```

<br />

Disable system data sync for an associated device.

For Android versions prior to `https://developer.android.com/reference/android/os/Build.VERSION_CODES#CINNAMON_BUN`,
only the following flags are supported:

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_CALL_METADATA`

<br />

Android versions above `https://developer.android.com/reference/android/os/Build.VERSION_CODES#CINNAMON_BUN` supports
the following additional flags, each of which has its own default toggle state and
may require specific permissions:

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_TASK_CONTINUITY`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_UNIVERSAL_MODES`
- `https://developer.android.com/`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_AIRPLANE_MODE`

<br />

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: id of the device association. <br /> |
| `flags` | `int`: system data types to be disabled. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_CALL_METADATA` - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_TASK_CONTINUITY` - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_UNIVERSAL_MODES` - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_AIRPLANE_MODE` |

### disassociate

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

```
public void disassociate (int associationId)
```

Remove an association.

Any privileges provided via being associated with a given device will be revoked

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: id of the association to be removed. <br /> |

**See also:**

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.Callback)`
- `https://developer.android.com/reference/android/companion/AssociationInfo#getId()`

### disassociate

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

```
public void disassociate (String deviceMacAddress)
```


**This method was deprecated
in API level 33.**   

use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#disassociate(int)`

Remove the association between this app and the device with the given mac address.

Any privileges provided via being associated with a given device will be revoked

Consider doing so when the
association is no longer relevant to avoid unnecessary battery and/or data drain resulting
from special privileges that the association provides

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Parameters ||
|---|---|
| `deviceMacAddress` | `String`: the MAC address of device to disassociate from this app. Device address is case-sensitive in API level \< 33. This value cannot be `null`. <br /> |

### enableSystemDataSyncForTypes

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

```
public void enableSystemDataSyncForTypes (int associationId, 
                int flags)
```

<br />

Enable system data sync for an associated device.

For Android versions prior to `https://developer.android.com/reference/android/os/Build.VERSION_CODES#CINNAMON_BUN`,
only the following flags are supported:

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_CALL_METADATA`

<br />

Android versions above `https://developer.android.com/reference/android/os/Build.VERSION_CODES#CINNAMON_BUN` supports
the following additional flags, each of which has its own default toggle state and
may require specific permissions:

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_TASK_CONTINUITY`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_UNIVERSAL_MODES`
- `https://developer.android.com/`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_AIRPLANE_MODE`

<br />

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: id of the device association. <br /> |
| `flags` | `int`: system data types to be enabled. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_CALL_METADATA` - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_TASK_CONTINUITY` - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_UNIVERSAL_MODES` - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#FLAG_AIRPLANE_MODE` |

### getAssociations

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

```
public List<String> getAssociations ()
```


**This method was deprecated
in API level 33.**   

use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#getMyAssociations()`

<br />

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/String>` | a list of MAC addresses of devices that have been previously associated with the current app are managed by CompanionDeviceManager (ie. does not include devices managed by application itself even if they have a MAC address). This value cannot be `null`. <br /> |

### getMyAssociations

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

```
public List<AssociationInfo> getMyAssociations ()
```

<br />

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/companion/AssociationInfo>` | a list of associations that have been previously associated with the current app. This value cannot be `null`. <br /> |

### hasNotificationAccess

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

```
public boolean hasNotificationAccess (ComponentName component)
```


**This method was deprecated
in API level 33.**   

Use
`https://developer.android.com/reference/android/app/NotificationManager#isNotificationListenerAccessGranted(android.content.ComponentName)` instead.

Check whether the given component can access the notifications via a
`https://developer.android.com/reference/android/service/notification/NotificationListenerService`

Your app must have an association with a device before calling this API

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Parameters ||
|---|---|
| `component` | `ComponentName`: the name of the component <br /> |

| Returns ||
|---|---|
| `boolean` | whether the given component has the notification listener permission <br /> |

### isPermissionTransferUserConsented

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

```
public boolean isPermissionTransferUserConsented (int associationId)
```

Return the current state of consent for permission transfer for the association.
True if the user has allowed permission transfer for the association, false otherwise.


Note: The initial user consent is collected via
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#buildPermissionTransferUserConsentIntent(int)`.
After the user has made their initial selection, they can toggle the permission transfer
feature in the settings.
This method always returns the state of the toggle setting.

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: The unique `https://developer.android.com/reference/android/companion/AssociationInfo#getId()` assigned to the association of the companion device recorded by CompanionDeviceManager <br /> |

| Returns ||
|---|---|
| `boolean` | True if the user has consented to the permission transfer, or false otherwise. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/companion/DeviceNotAssociatedException` | Exception if the companion device is not associated with the user or the calling app. |

### isSystemDataTransportAttached

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

```
public boolean isSystemDataTransportAttached (int associationId)
```

Checks if a transport is currently attached for a given association id.

A transport is considered attached if
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#attachSystemDataTransport(int,%20java.io.InputStream,%20java.io.OutputStream)` has been successfully
called for the given `associationId`, and
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#detachSystemDataTransport(int)` has not yet been called.

This is useful for determining if the system is ready to handle data transfers
before calling `https://developer.android.com/reference/android/companion/CompanionDeviceManager#startSystemDataTransfer(int,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>)`.

The caller must meet one of the following requirements:

- It is the package that originally created the association.
- It holds the `android.permission.ACCESS_COMPANION_MESSAGE_PCC` permission and the association must be verified as a `https://developer.android.com/reference/android/companion/AssociationInfo#isTrusted()`

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: The unique `https://developer.android.com/reference/android/companion/AssociationInfo#getId()` of the device association <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if a system data transport is attached for the given association id, `false` otherwise. <br /> |

**See also:**

- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#attachSystemDataTransport(int,%20java.io.InputStream,%20java.io.OutputStream)`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#detachSystemDataTransport(int)`
- `https://developer.android.com/reference/android/companion/CompanionDeviceManager#startSystemDataTransfer(int,%20java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,android.companion.CompanionException>)`
- `https://developer.android.com/reference/android/companion/AssociationInfo#isTrusted()`

### notifyActionResult

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

```
public void notifyActionResult (int associationId, 
                ActionResult result)
```

Allows a companion app to report the result of an action that was requested by the system.


This API should be called after the app has received a request via
`https://developer.android.com/reference/android/companion/CompanionDeviceService#onActionRequested(android.companion.AssociationInfo,%20android.companion.ActionRequest)`.

For example:

- After receiving `https://developer.android.com/reference/android/companion/ActionRequest#OP_ACTIVATE`, the app should call this method with `https://developer.android.com/reference/android/companion/ActionResult#RESULT_ACTIVATED` upon success or `https://developer.android.com/reference/android/companion/ActionResult#RESULT_FAILED_TO_ACTIVATE` upon failure.
- If a previously activated feature later fails or stops for any reason, the app should proactively call this method with `https://developer.android.com/reference/android/companion/ActionResult#RESULT_DEACTIVATED`.

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int` <br /> |
| `result` | `ActionResult`: The `https://developer.android.com/reference/android/companion/ActionResult` to report to the system. This value cannot be `null`. <br /> |

### removeBond

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

```
public boolean removeBond (int associationId)
```

Remove bonding between this device and an associated companion device.

This is an asynchronous call, it will return immediately. Register for `https://developer.android.com/reference/android/bluetooth/BluetoothDevice#ACTION_BOND_STATE_CHANGED` intents to be notified when the bond removal
process completes, and its result.

This API should be used to remove a bluetooth bond that was created either
by using `https://developer.android.com/reference/android/bluetooth/BluetoothDevice#createBond()` or by a direct user action.
The association must already exist with this device before calling this method, but
this may be done retroactively to remove a bond that was created outside of the
CompanionDeviceManager.


Requires `https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT`

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: an already-associated companion device to remove bond from <br /> |

| Returns ||
|---|---|
| `boolean` | false on immediate error, true if bond removal process will begin <br /> |

### requestDeviceTrustPairing

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void requestDeviceTrustPairing (int associationId, 
                OutOfBandPairingRequest requestOobPairing, 
                int[] trustTypes, 
                Executor executor, 
                CompanionDeviceManager.TrustPairingCallback callback)
```

Request the system to initiate a trusted pairing process for the given association. This
process is required to enable certain features that demand a higher level of trust between
the devices.

The outcome of the pairing process will be delivered via the provided
`https://developer.android.com/reference/android/companion/CompanionDeviceManager.TrustPairingCallback`. The callback will first receive
`https://developer.android.com/reference/android/companion/CompanionDeviceManager.TrustPairingCallback#onTrustPairingPending(android.content.IntentSender)` with an `https://developer.android.com/reference/android/content/IntentSender`
to launch a user confirmation dialog. Upon user confirmation and successful pairing,
`https://developer.android.com/reference/android/companion/CompanionDeviceManager.TrustPairingCallback#onDeviceTrusted(android.companion.AssociationInfo)` will be invoked. If the
process fails or is canceled, `https://developer.android.com/reference/android/companion/CompanionDeviceManager.TrustPairingCallback#onFailure(int)` or
`https://developer.android.com/reference/android/companion/CompanionDeviceManager.TrustPairingCallback#onTrustPairingCanceledFromRemote(android.companion.AssociationInfo,%20android.content.IntentSender)`
will be called.

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: the unique `https://developer.android.com/reference/android/companion/AssociationInfo#getId()` assigned to the Association recorded by CompanionDeviceManager <br /> |
| `requestOobPairing` | `OutOfBandPairingRequest`: request for out-of-band pairing. This value may be `null`. <br /> |
| `trustTypes` | `int`: list of trust types to be enabled that require trust pairing (or an empty array if no trust types are requested). This value cannot be `null`. Value is one of the following: - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#TRUST_TYPE_SCREEN_AUTOMATION` - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#TRUST_TYPE_PROACTIVE_ASSISTANCE` - `https://developer.android.com/reference/android/companion/CompanionDeviceManager#TRUST_TYPE_CROSS_DEVICE_AUTHENTICATION` |
| `executor` | `Executor`: the executor to use for the callback. This value cannot be `null`. <br /> |
| `callback` | `CompanionDeviceManager.TrustPairingCallback`: the callback to be invoked for the pairing process. This value cannot be `null`. <br /> |

### requestNotificationAccess

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

```
public void requestNotificationAccess (ComponentName component)
```

Request notification access for the given component.

The given component must follow the protocol specified in `https://developer.android.com/reference/android/service/notification/NotificationListenerService`

Only components from the same `https://developer.android.com/reference/android/content/ComponentName#getPackageName()` as the calling app
are allowed.

Your app must have an association with a device before calling this API.

Side-loaded apps must allow restricted settings before requesting notification access.

Calling this API requires a uses-feature
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` declaration in the manifest

<br />

<br />

| Parameters ||
|---|---|
| `component` | `ComponentName` <br /> |

### setDeviceId

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

```
public void setDeviceId (int associationId, 
                DeviceId deviceId)
```


**This method was deprecated
in API level 36.1.**   

use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#createAndSetDeviceId(int,%20android.companion.DeviceId)` instead.

Sets the `https://developer.android.com/reference/android/companion/DeviceId` for this association.

This device id helps the system uniquely identify your device for efficient device
management and prevents duplicate entries.

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: The unique `https://developer.android.com/reference/android/companion/AssociationInfo#getId()` assigned to the Association of the companion device recorded by CompanionDeviceManager. <br /> |
| `deviceId` | `DeviceId`: to be used as device identifier to represent the associated device. This value may be `null`. <br /> |

### startObservingDevicePresence

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

```
public void startObservingDevicePresence (ObservingDevicePresenceRequest request)
```

Register to receive callbacks whenever the associated device's presence changes.
The presence could be:

- BLE range changes (in/out)
- Bluetooth connection status changes (connected/disconnected)

Caller app must implement the `https://developer.android.com/reference/android/companion/CompanionDeviceService` to receive callbacks via
`https://developer.android.com/reference/android/companion/CompanionDeviceService#onDevicePresenceEvent(android.companion.DevicePresenceEvent)`.
The system will bind to the implemented `https://developer.android.com/reference/android/companion/CompanionDeviceService` to deliver the
callbacks.

Calling app must check for feature presence of
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` before calling this API.

For Bluetooth LE devices, this is based on scanning for device with the given address.
The system will scan for the device when Bluetooth is ON or Bluetooth scanning is ON.

For Bluetooth classic devices this is triggered when the device connects/disconnects.

WiFi devices are not supported.

If a Bluetooth LE device wants to use a rotating mac address, it is recommended to use
Resolvable Private Address, and ensure the device is bonded to the phone so that android OS
is able to resolve the address.
.   
Requires `https://developer.android.com/reference/android/Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE`

<br />

<br />

| Parameters ||
|---|---|
| `request` | `ObservingDevicePresenceRequest`: A request for setting the types of device for observing device presence. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/companion/ObservingDevicePresenceRequest.Builder`
- `https://developer.android.com/reference/android/companion/CompanionDeviceService#onDevicePresenceEvent(android.companion.DevicePresenceEvent)`

### startObservingDevicePresence

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

```
public void startObservingDevicePresence (String deviceAddress)
```


**This method was deprecated
in API level 36.**   

use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#startObservingDevicePresence(android.companion.ObservingDevicePresenceRequest)`
instead.

Register to receive callbacks whenever the associated device comes in and out of range.

The provided device must be `https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20android.companion.CompanionDeviceManager.Callback,%20android.os.Handler)` with the calling app before
calling this method.

Caller must implement a single `https://developer.android.com/reference/android/companion/CompanionDeviceService` which will be bound to and
receive callbacks to `https://developer.android.com/reference/android/companion/CompanionDeviceService#onDeviceAppeared(android.companion.AssociationInfo)` and
`https://developer.android.com/reference/android/companion/CompanionDeviceService#onDeviceDisappeared(android.companion.AssociationInfo)`.
The app doesn't need to remain running in order to receive its callbacks.

Calling app must declare uses-permission
`https://developer.android.com/reference/android/Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE`.

Calling app must check for feature presence of
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` before calling this API.

For Bluetooth LE devices, this is based on scanning for device with the given address.
The system will scan for the device when Bluetooth is ON or Bluetooth scanning is ON.

For Bluetooth classic devices this is triggered when the device connects/disconnects.
WiFi devices are not supported.

If a Bluetooth LE device wants to use a rotating mac address, it is recommended to use
Resolvable Private Address, and ensure the device is bonded to the phone so that android OS
is able to resolve the address.
.   
Requires `https://developer.android.com/reference/android/Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE`

<br />

<br />

| Parameters ||
|---|---|
| `deviceAddress` | `String`: a previously-associated companion device's address. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/companion/DeviceNotAssociatedException` | if the given device was not previously associated with this app. |

### startSystemDataTransfer

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

```
public void startSystemDataTransfer (int associationId, 
                Executor executor, 
                OutcomeReceiver<Void, CompanionException> result)
```

Start system data transfer which has been previously approved by the user.

Before calling this method, the app needs to make sure
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#attachSystemDataTransport(int,%20java.io.InputStream,%20java.io.OutputStream)`, and
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#buildPermissionTransferUserConsentIntent(int)`.
The transfer will fail if the transport channel is disconnected or
`https://developer.android.com/reference/android/companion/CompanionDeviceManager#detachSystemDataTransport(int)` during the transfer.

<br />

<br />

| Parameters ||
|---|---|
| `associationId` | `int`: The unique `https://developer.android.com/reference/android/companion/AssociationInfo#getId()` assigned to the Association of the companion device recorded by CompanionDeviceManager <br /> |
| `executor` | `Executor`: The executor which will be used to invoke the result callback. This value cannot be `null`. <br /> |
| `result` | `OutcomeReceiver`: The callback to notify the app of the result of the system data transfer. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/companion/DeviceNotAssociatedException` | Exception if the companion device is not associated |

### stopObservingDevicePresence

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

```
public void stopObservingDevicePresence (String deviceAddress)
```


**This method was deprecated
in API level 36.**   

use `https://developer.android.com/reference/android/companion/CompanionDeviceManager#stopObservingDevicePresence(android.companion.ObservingDevicePresenceRequest)`
instead.

Unregister for receiving callbacks whenever the associated device comes in and out of range.

The provided device must be `https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20android.companion.CompanionDeviceManager.Callback,%20android.os.Handler)` with the calling app before
calling this method.

Calling app must declare uses-permission
`https://developer.android.com/reference/android/Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE`.

Calling app must check for feature presence of
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` before calling this API.


Requires `https://developer.android.com/reference/android/Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE`

<br />

| Parameters ||
|---|---|
| `deviceAddress` | `String`: a previously-associated companion device's address. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/companion/DeviceNotAssociatedException` | if the given device was not previously associated with this app. |

### stopObservingDevicePresence

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

```
public void stopObservingDevicePresence (ObservingDevicePresenceRequest request)
```

Unregister for receiving callbacks whenever the associated device comes in and out of range.

Calling app must check for feature presence of
`https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_COMPANION_DEVICE_SETUP` before calling this API.


Requires `https://developer.android.com/reference/android/Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE`

<br />

| Parameters ||
|---|---|
| `request` | `ObservingDevicePresenceRequest`: A request for setting the types of device for observing device presence. This value cannot be `null`. <br /> |