# CompanionDeviceManager.Callback

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

# CompanionDeviceManager.Callback

*** ** * ** ***

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

`
public
static

abstract
class
CompanionDeviceManager.Callback
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

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

<br />

*** ** * ** ***

Callback for applications to receive updates about and the outcome of[AssociationRequest](https://developer.android.com/reference/android/companion/AssociationRequest)issued via`associate()`call.

The[Callback.onAssociationPending(IntentSender)](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onAssociationPending(android.content.IntentSender))is invoked after the[AssociationRequest](https://developer.android.com/reference/android/companion/AssociationRequest)has been checked by the Companion Device Manager Service and is pending user's approval. The[IntentSender](https://developer.android.com/reference/android/content/IntentSender)received as an argument to[Callback.onAssociationPending(IntentSender)](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onAssociationPending(android.content.IntentSender))"encapsulates" an[Activity](https://developer.android.com/reference/android/app/Activity)that has UI for the user to:

- choose the device to associate the application with (if multiple eligible devices are available)
- confirm the association
- approve the privileges the application will be granted if the association is to be created

If the Companion Device Manager Service needs to scan for the devices, the[Activity](https://developer.android.com/reference/android/app/Activity)will also display the status and the progress of the scan. Note that Companion Device Manager Service will only start the scanning after the[Activity](https://developer.android.com/reference/android/app/Activity)was launched and became visible. Applications are expected to launch the UI using the received[IntentSender](https://developer.android.com/reference/android/content/IntentSender)via[Activity.startIntentSenderForResult(IntentSender, int, Intent, int, int, int)](https://developer.android.com/reference/android/app/Activity#startIntentSenderForResult(android.content.IntentSender,%20int,%20android.content.Intent,%20int,%20int,%20int)).

<br />

Upon receiving user's confirmation Companion Device Manager Service will create an association and will send an[AssociationInfo](https://developer.android.com/reference/android/companion/AssociationInfo)object that represents the created association back to the application both via[Callback.onAssociationCreated(AssociationInfo)](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onAssociationCreated(android.companion.AssociationInfo))and via[Activity.setResult(int, Intent)](https://developer.android.com/reference/android/app/Activity#setResult(int,%20android.content.Intent)). In the latter the`resultCode`will be set to[Activity.RESULT_OK](https://developer.android.com/reference/android/app/Activity#RESULT_OK)and the`data`[Intent](https://developer.android.com/reference/android/content/Intent)will contain[AssociationInfo](https://developer.android.com/reference/android/companion/AssociationInfo)extra named[CompanionDeviceManager.EXTRA_ASSOCIATION](https://developer.android.com/reference/android/companion/CompanionDeviceManager#EXTRA_ASSOCIATION).  

     
       if (resultCode == Activity.RESULT_OK) {
         AssociationInfo associationInfo = data.getParcelableExtra(EXTRA_ASSOCIATION);
       }
     
     
<br />

If the Companion Device Manager Service is not able to create an association, it will invoke[Callback.onFailure(CharSequence)](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onFailure(java.lang.CharSequence)). If this happened after the application has launched the UI (eg. the user chose to reject the association), the outcome will also be delivered to the applications via[Activity.setResult(int)](https://developer.android.com/reference/android/app/Activity#setResult(int))with the[Activity.RESULT_CANCELED](https://developer.android.com/reference/android/app/Activity#RESULT_CANCELED)`resultCode`.

Note that in some cases the Companion Device Manager Service may not need to collect user's approval for creating an association. In such cases, this method will not be invoked, and[onAssociationCreated(android.companion.AssociationInfo)](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onAssociationCreated(android.companion.AssociationInfo))may be invoked right away.

<br />

**See also:**

- [CompanionDeviceManager.associate(AssociationRequest, Executor, Callback)](https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20java.util.concurrent.Executor,%20android.companion.CompanionDeviceManager.Callback))
- [CompanionDeviceManager.associate(AssociationRequest, Callback, Handler)](https://developer.android.com/reference/android/companion/CompanionDeviceManager#associate(android.companion.AssociationRequest,%20android.companion.CompanionDeviceManager.Callback,%20android.os.Handler))
- [CompanionDeviceManager.EXTRA_ASSOCIATION](https://developer.android.com/reference/android/companion/CompanionDeviceManager#EXTRA_ASSOCIATION)

## Summary

|                                                   ### Public constructors                                                   ||
|--------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Callback](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#Callback())`() ` |

|                                                                                                                                                                                                                                   ### Public methods                                                                                                                                                                                                                                    ||
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`          | ` `[onAssociationCreated](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onAssociationCreated(android.companion.AssociationInfo))`(`[AssociationInfo](https://developer.android.com/reference/android/companion/AssociationInfo)` associationInfo) ` Invoked when the association is created.                                                                                                                              |
| ` void`          | ` `[onAssociationPending](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onAssociationPending(android.content.IntentSender))`(`[IntentSender](https://developer.android.com/reference/android/content/IntentSender)` intentSender) ` Invoked when the association needs to approved by the user.                                                                                                                           |
| ` void`          | ` `[onDeviceFound](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onDeviceFound(android.content.IntentSender))`(`[IntentSender](https://developer.android.com/reference/android/content/IntentSender)` intentSender) ` *This method was deprecated in API level 33. method was renamed to onAssociationPending() to provide better clarity; both methods are functionally equivalent and only one needs to be overridden.* |
| ` void`          | ` `[onFailure](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onFailure(int,%20java.lang.CharSequence))`(int errorCode, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` error) ` Invoked if the association could not be created.                                                                                                                                                         |
| ` abstract void` | ` `[onFailure](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onFailure(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` error) ` Invoked if the association could not be created.                                                                                                                                                                               |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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*.                                                                                             | ||

## Public constructors

### Callback

```
public Callback ()
```

<br />

<br />

## Public methods

### onAssociationCreated

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

```
public void onAssociationCreated (AssociationInfo associationInfo)
```

Invoked when the association is created.

<br />

|                                                           Parameters                                                            ||
|-------------------|--------------------------------------------------------------------------------------------------------------|
| `associationInfo` | `AssociationInfo`: contains details of the newly-established association. This value cannot be`null`. <br /> |

### onAssociationPending

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

```
public void onAssociationPending (IntentSender intentSender)
```

Invoked when the association needs to approved by the user. Applications should launch the[Activity](https://developer.android.com/reference/android/app/Activity)"encapsulated" in`intentSender`[IntentSender](https://developer.android.com/reference/android/content/IntentSender)object by calling[Activity.startIntentSenderForResult(IntentSender, int, Intent, int, int, int)](https://developer.android.com/reference/android/app/Activity#startIntentSenderForResult(android.content.IntentSender,%20int,%20android.content.Intent,%20int,%20int,%20int)).

<br />

|                                                                                                                    Parameters                                                                                                                    ||
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `intentSender` | `IntentSender`: an[IntentSender](https://developer.android.com/reference/android/content/IntentSender)which applications should use to launch the UI for the user to confirm the association. This value cannot be`null`. <br /> |

### onDeviceFound

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 onDeviceFound (IntentSender intentSender)
```

<br />

**This method was deprecated in API level 33.**   
method was renamed to onAssociationPending() to provide better clarity; both methods are functionally equivalent and only one needs to be overridden.

<br />

<br />

|                             Parameters                             ||
|----------------|----------------------------------------------------|
| `intentSender` | `IntentSender`: This value cannot be`null`. <br /> |

**See also:**

- [onAssociationPending(IntentSender)](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onAssociationPending(android.content.IntentSender))  

### onFailure

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

```
public void onFailure (int errorCode, 
                CharSequence error)
```

Invoked if the association could not be created. Please note that both[onFailure(java.lang.CharSequence)](https://developer.android.com/reference/android/companion/CompanionDeviceManager.Callback#onFailure(java.lang.CharSequence))and this API will be called if the association could not be created.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                              Parameters                                                                                                                                                                                                                                                                                                                                                                                                                               ||
|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `errorCode` | `int`: indicate the particular error code why the association could not be created. Value is[CompanionDeviceManager.RESULT_OK](https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_OK),[CompanionDeviceManager.RESULT_CANCELED](https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_CANCELED),[CompanionDeviceManager.RESULT_USER_REJECTED](https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_USER_REJECTED),[CompanionDeviceManager.RESULT_DISCOVERY_TIMEOUT](https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_DISCOVERY_TIMEOUT), or[CompanionDeviceManager.RESULT_INTERNAL_ERROR](https://developer.android.com/reference/android/companion/CompanionDeviceManager#RESULT_INTERNAL_ERROR) <br /> |
| `error`     | `CharSequence`: error message. This value may be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

### onFailure

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

```
public abstract void onFailure (CharSequence error)
```

Invoked if the association could not be created.

<br />

|                               Parameters                                ||
|---------|----------------------------------------------------------------|
| `error` | `CharSequence`: error message. This value may be`null`. <br /> |