Share via


WifiAwareManager.Attach Method

Definition

Overloads

Attach(AttachCallback, Handler)

Attach to the Wi-Fi Aware service - enabling the application to create discovery sessions or create connections to peers.

Attach(AttachCallback, IdentityChangedListener, Handler)

Attach to the Wi-Fi Aware service - enabling the application to create discovery sessions or create connections to peers.

Attach(AttachCallback, Handler)

Attach to the Wi-Fi Aware service - enabling the application to create discovery sessions or create connections to peers.

[Android.Runtime.Register("attach", "(Landroid/net/wifi/aware/AttachCallback;Landroid/os/Handler;)V", "GetAttach_Landroid_net_wifi_aware_AttachCallback_Landroid_os_Handler_Handler", ApiSince=26)]
public virtual void Attach (Android.Net.Wifi.Aware.AttachCallback attachCallback, Android.OS.Handler? handler);
[<Android.Runtime.Register("attach", "(Landroid/net/wifi/aware/AttachCallback;Landroid/os/Handler;)V", "GetAttach_Landroid_net_wifi_aware_AttachCallback_Landroid_os_Handler_Handler", ApiSince=26)>]
abstract member Attach : Android.Net.Wifi.Aware.AttachCallback * Android.OS.Handler -> unit
override this.Attach : Android.Net.Wifi.Aware.AttachCallback * Android.OS.Handler -> unit

Parameters

attachCallback
AttachCallback

A callback for attach events, extended from AttachCallback.

handler
Handler

The Handler on whose thread to execute the callbacks of the attachCallback object. If a null is provided then the application's main thread will be used.

Attributes

Remarks

Attach to the Wi-Fi Aware service - enabling the application to create discovery sessions or create connections to peers. The device will attach to an existing cluster if it can find one or create a new cluster (if it is the first to enable Aware in its vicinity). Results (e.g. successful attach to a cluster) are provided to the attachCallback object. An application <b>must</b> call WifiAwareSession#close() when done with the Wi-Fi Aware object.

Note: a Aware cluster is a shared resource - if the device is already attached to a cluster then this function will simply indicate success immediately using the same attachCallback.

Java documentation for android.net.wifi.aware.WifiAwareManager.attach(android.net.wifi.aware.AttachCallback, android.os.Handler).

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

Attach(AttachCallback, IdentityChangedListener, Handler)

Attach to the Wi-Fi Aware service - enabling the application to create discovery sessions or create connections to peers.

[Android.Runtime.Register("attach", "(Landroid/net/wifi/aware/AttachCallback;Landroid/net/wifi/aware/IdentityChangedListener;Landroid/os/Handler;)V", "GetAttach_Landroid_net_wifi_aware_AttachCallback_Landroid_net_wifi_aware_IdentityChangedListener_Landroid_os_Handler_Handler", ApiSince=26)]
public virtual void Attach (Android.Net.Wifi.Aware.AttachCallback attachCallback, Android.Net.Wifi.Aware.IdentityChangedListener identityChangedListener, Android.OS.Handler? handler);
[<Android.Runtime.Register("attach", "(Landroid/net/wifi/aware/AttachCallback;Landroid/net/wifi/aware/IdentityChangedListener;Landroid/os/Handler;)V", "GetAttach_Landroid_net_wifi_aware_AttachCallback_Landroid_net_wifi_aware_IdentityChangedListener_Landroid_os_Handler_Handler", ApiSince=26)>]
abstract member Attach : Android.Net.Wifi.Aware.AttachCallback * Android.Net.Wifi.Aware.IdentityChangedListener * Android.OS.Handler -> unit
override this.Attach : Android.Net.Wifi.Aware.AttachCallback * Android.Net.Wifi.Aware.IdentityChangedListener * Android.OS.Handler -> unit

Parameters

attachCallback
AttachCallback

A callback for attach events, extended from AttachCallback.

identityChangedListener
IdentityChangedListener

A callback for changed identity or cluster ID, extended from IdentityChangedListener.

handler
Handler

The Handler on whose thread to execute the callbacks of the attachCallback and identityChangedListener objects. If a null is provided then the application's main thread will be used.

Attributes

Remarks

Attach to the Wi-Fi Aware service - enabling the application to create discovery sessions or create connections to peers. The device will attach to an existing cluster if it can find one or create a new cluster (if it is the first to enable Aware in its vicinity). Results (e.g. successful attach to a cluster) are provided to the attachCallback object. An application <b>must</b> call WifiAwareSession#close() when done with the Wi-Fi Aware object.

Note: a Aware cluster is a shared resource - if the device is already attached to a cluster then this function will simply indicate success immediately using the same attachCallback.

This version of the API attaches a listener to receive the MAC address of the Aware interface on startup and whenever it is updated (it is randomized at regular intervals for privacy).

If targeting android.os.Build.VERSION_CODES#TIRAMISU or later, the application must have android.Manifest.permission#NEARBY_WIFI_DEVICES with android:usesPermissionFlags="neverForLocation". If the application does not declare android:usesPermissionFlags="neverForLocation", then it must also have android.Manifest.permission#ACCESS_FINE_LOCATION.

If targeting an earlier release than android.os.Build.VERSION_CODES#TIRAMISU, the application must have android.Manifest.permission#ACCESS_FINE_LOCATION.

Apps without android.Manifest.permission#NEARBY_WIFI_DEVICES or android.Manifest.permission#ACCESS_FINE_LOCATION can use the #attach(AttachCallback, Handler) version. Note that aside from permission requirements the IdentityChangedListener will wake up the host at regular intervals causing higher power consumption, do not use it unless the information is necessary (e.g. for out-of-band discovery).

Java documentation for android.net.wifi.aware.WifiAwareManager.attach(android.net.wifi.aware.AttachCallback, android.net.wifi.aware.IdentityChangedListener, android.os.Handler).

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