CompanionDeviceManager.Associate Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| Associate(AssociationRequest, CompanionDeviceManager+Callback, Handler) |
Associate this app with a companion device, selected by user |
| Associate(AssociationRequest, IExecutor, CompanionDeviceManager+Callback) |
Request to associate this app with a companion device. |
Associate(AssociationRequest, CompanionDeviceManager+Callback, Handler)
Associate this app with a companion device, selected by user
[Android.Runtime.Register("associate", "(Landroid/companion/AssociationRequest;Landroid/companion/CompanionDeviceManager$Callback;Landroid/os/Handler;)V", "", ApiSince=26)]
public void Associate(Android.Companion.AssociationRequest request, Android.Companion.CompanionDeviceManager.Callback callback, Android.OS.Handler? handler);
[<Android.Runtime.Register("associate", "(Landroid/companion/AssociationRequest;Landroid/companion/CompanionDeviceManager$Callback;Landroid/os/Handler;)V", "", ApiSince=26)>]
member this.Associate : Android.Companion.AssociationRequest * Android.Companion.CompanionDeviceManager.Callback * Android.OS.Handler -> unit
Parameters
- request
- AssociationRequest
specific details about this request
- callback
- CompanionDeviceManager.Callback
will be called once there's at least one device found for user to choose from
- handler
- Handler
A handler to control which thread the callback will be delivered on, or null, to deliver it on main thread
- Attributes
Remarks
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
Associate(AssociationRequest, IExecutor, CompanionDeviceManager+Callback)
Request to associate this app with a companion device.
[Android.Runtime.Register("associate", "(Landroid/companion/AssociationRequest;Ljava/util/concurrent/Executor;Landroid/companion/CompanionDeviceManager$Callback;)V", "", ApiSince=33)]
public void Associate(Android.Companion.AssociationRequest request, Java.Util.Concurrent.IExecutor executor, Android.Companion.CompanionDeviceManager.Callback callback);
[<Android.Runtime.Register("associate", "(Landroid/companion/AssociationRequest;Ljava/util/concurrent/Executor;Landroid/companion/CompanionDeviceManager$Callback;)V", "", ApiSince=33)>]
member this.Associate : Android.Companion.AssociationRequest * Java.Util.Concurrent.IExecutor * Android.Companion.CompanionDeviceManager.Callback -> unit
Parameters
- request
- AssociationRequest
A request object that describes details of the request. This value cannot be null.
- executor
- IExecutor
The executor which will be used to invoke the callback. This value cannot be null.
- callback
- CompanionDeviceManager.Callback
The callback used to notify application when the association is created. This value cannot be null.
- Attributes
Remarks
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 Manifest.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND and 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 getMyAssociations() for retrieving the list of currently AssociationInfo objects, that represent their existing associations. Applications can also use 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.
Calling this API requires a uses-feature PackageManager.FEATURE_COMPANION_DEVICE_SETUP declaration in the manifest
Android reference for android.companion.CompanionDeviceManager.associate.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.