CompanionDeviceManager.Callback  |  API reference  |  Android Developers (original) (raw)

Summary:Ctors | Methods | Inherited Methods


public static abstract class CompanionDeviceManager.Callback
extends [Object](/reference/java/lang/Object) ``


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

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

If the Companion Device Manager Service needs to scan for the devices, the [Activity](/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](/reference/android/app/Activity) was launched and became visible. Applications are expected to launch the UI using the received [IntentSender](/reference/android/content/IntentSender) via[Activity.startIntentSenderForResult(IntentSender,int,Intent,int,int,int)](/reference/android/app/Activity#startIntentSenderForResult%28android.content.IntentSender,%20int,%20android.content.Intent,%20int,%20int,%20int%29).

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

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

If the Companion Device Manager Service is not able to create an association, it will invoke [Callback.onFailure(CharSequence)](/reference/android/companion/CompanionDeviceManager.Callback#onFailure%28java.lang.CharSequence%29). 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)](/reference/android/app/Activity#setResult%28int%29) with the [Activity.RESULT_CANCELED](/reference/android/app/Activity#RESULT%5FCANCELED) 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(AssociationInfo)](/reference/android/companion/CompanionDeviceManager.Callback#onAssociationCreated%28android.companion.AssociationInfo%29) may be invoked right away.

See also:

Summary

Public constructors
Callback()
Public methods
void onAssociationCreated(AssociationInfo associationInfo) Invoked when the association is created.
void onAssociationPending(IntentSender intentSender) Invoked when the association needs to approved by the user.
void onDeviceFound(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(int errorCode, CharSequence error) Invoked if the association could not be created.
abstract void onFailure(CharSequence error) Invoked if the association could not be created.
Inherited methods
From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(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(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() Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public constructors

Callback

public Callback ()

Public methods

onAssociationCreated

public void onAssociationCreated (AssociationInfo associationInfo)

Invoked when the association is created.

Parameters
associationInfo AssociationInfo: contains details of the newly-established association. This value cannot be null.

onDeviceFound

public void onDeviceFound (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.

Parameters
intentSender IntentSender: This value cannot be null.

onFailure

public abstract void onFailure (CharSequence error)

Invoked if the association could not be created.

Parameters
error CharSequence: error message. This value may be null.