Language

WifiP2pManager Class

Definition

This class provides the API for managing Wi-Fi peer-to-peer connectivity.

[Android.Runtime.Register("android/net/wifi/p2p/WifiP2pManager", DoNotGenerateAcw=true)]
public class WifiP2pManager : Java.Lang.Object
[<Android.Runtime.Register("android/net/wifi/p2p/WifiP2pManager", DoNotGenerateAcw=true)>]
type WifiP2pManager = class
    inherit Object
Inheritance
WifiP2pManager
Attributes

Remarks

This class provides the API for managing Wi-Fi peer-to-peer connectivity. This lets an application discover available peers, setup connection to peers and query for the list of peers. When a p2p connection is formed over wifi, the device continues to maintain the uplink connection over mobile or any other available network for internet connectivity on the device.

The API is asynchronous and responses to requests from an application are on listener callbacks provided by the application. The application needs to do an initialization with #initialize before doing any p2p operation.

Most application calls need a ActionListener instance for receiving callbacks ActionListener#onSuccess or ActionListener#onFailure. Action callbacks indicate whether the initiation of the action was a success or a failure. Upon failure, the reason of failure can be one of #ERROR, #P2P_UNSUPPORTED or #BUSY.

An application can initiate discovery of peers with #discoverPeers. An initiated discovery request from an application stays active until the device starts connecting to a peer ,forms a p2p group or there is an explicit #stopPeerDiscovery. Applications can listen to #WIFI_P2P_DISCOVERY_CHANGED_ACTION to know if a peer-to-peer discovery is running or stopped. Additionally, #WIFI_P2P_PEERS_CHANGED_ACTION indicates if the peer list has changed.

When an application needs to fetch the current list of peers, it can request the list of peers with #requestPeers. When the peer list is available PeerListListener#onPeersAvailable is called with the device list.

An application can initiate a connection request to a peer through #connect. See WifiP2pConfig for details on setting up the configuration. For communication with legacy Wi-Fi devices that do not support p2p, an app can create a group using #createGroup which creates an access point whose details can be fetched with #requestGroupInfo.

After a successful group formation through #createGroup or through #connect, use #requestConnectionInfo to fetch the connection details. The connection info WifiP2pInfo contains the address of the group owner WifiP2pInfo#groupOwnerAddress and a flag WifiP2pInfo#isGroupOwner to indicate if the current device is a p2p group owner. A p2p client can thus communicate with the p2p group owner through a socket connection. If the current device is the p2p group owner, WifiP2pInfo#groupOwnerAddress is anonymized unless the caller holds the android.Manifest.permission#LOCAL_MAC_ADDRESS permission.

With peer discovery using #discoverPeers, an application discovers the neighboring peers, but has no good way to figure out which peer to establish a connection with. For example, if a game application is interested in finding all the neighboring peers that are also running the same game, it has no way to find out until after the connection is setup. Pre-association service discovery is meant to address this issue of filtering the peers based on the running services.

With pre-association service discovery, an application can advertise a service for a application on a peer device prior to a connection setup between the devices. Currently, DNS based service discovery (Bonjour) and Upnp are the higher layer protocols supported. Get Bonjour resources at dns-sd.org and Upnp resources at upnp.org As an example, a video application can discover a Upnp capable media renderer prior to setting up a Wi-fi p2p connection with the device.

An application can advertise a Upnp or a Bonjour service with a call to #addLocalService. After a local service is added, the framework automatically responds to a peer application discovering the service prior to establishing a p2p connection. A call to #removeLocalService removes a local service and #clearLocalServices can be used to clear all local services.

An application that is looking for peer devices that support certain services can do so with a call to #discoverServices. Prior to initiating the discovery, application can add service discovery request with a call to #addServiceRequest, remove a service discovery request with a call to #removeServiceRequest or clear all requests with a call to #clearServiceRequests. When no service requests remain, a previously running service discovery will stop.

The application is notified of a result of service discovery request through listener callbacks set through #setDnsSdResponseListeners for Bonjour or #setUpnpServiceResponseListener for Upnp.

Note: Registering an application handler with #initialize requires the permissions android.Manifest.permission#ACCESS_WIFI_STATE and android.Manifest.permission#CHANGE_WIFI_STATE to perform any further peer-to-peer operations.

WifiP2pConfigWifiP2pInfoWifiP2pGroupWifiP2pDeviceWifiP2pDeviceListandroid.net.wifi.WpsInfo

Java documentation for android.net.wifi.p2p.WifiP2pManager.

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.

Constructors

Name Description
WifiP2pManager(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

Name Description
ActionWifiP2pListenStateChanged

Broadcast intent action indicating that peer listen has either started or stopped.

ActionWifiP2pRequestResponseChanged

Broadcast intent action indicating whether or not current connecting request is accepted.

Busy
Obsolete.

Passed with ActionListener#onFailure.

ConnectionRequestAccept
Obsolete.

Accept the incoming request.

ConnectionRequestDeferShowPasswordToService
Obsolete.

Defer the Wi-Fi Direct R2 pairing bootstrapping password display to the Wi-Fi service (which will display a dialog to the user).

ConnectionRequestDeferShowPinToService
Obsolete.

Defer the WPS PIN or Wi-Fi Direct R2 pairing bootstrapping PIN display to the Wi-Fi service (which will display a dialog to the user).

ConnectionRequestDeferToService
Obsolete.

Defer the decision back to the Wi-Fi service (which will display a dialog to the user).

ConnectionRequestReject
Obsolete.

Reject the incoming request.

Error
Obsolete.

Passed with ActionListener#onFailure.

ExtraDiscoveryState

The lookup key for an int that indicates whether p2p discovery has started or stopped.

ExtraListenState

The lookup key for an int that indicates whether p2p listen has started or stopped.

ExtraNetworkInfo

The lookup key for a android.net.NetworkInfo object associated with the p2p network.

ExtraP2pDeviceList

The lookup key for a android.net.wifi.p2p.WifiP2pDeviceList object representing the new peer list when #WIFI_P2P_PEERS_CHANGED_ACTION broadcast is sent.

ExtraRequestConfig

The lookup key for the WifiP2pConfig object of a request.

ExtraRequestResponse

The lookup key for the result of a request, true if accepted, false otherwise.

ExtraWifiP2pDevice

The lookup key for a android.net.wifi.p2p.WifiP2pDevice object Retrieve with android.content.Intent#getParcelableExtra(String).

ExtraWifiP2pGroup

The lookup key for a android.net.wifi.p2p.WifiP2pGroup object associated with the p2p network.

ExtraWifiP2pInfo

The lookup key for a android.net.wifi.p2p.WifiP2pInfo object Retrieve with android.content.Intent#getParcelableExtra(String).

ExtraWifiState

The lookup key for an int that indicates whether Wi-Fi p2p is enabled or disabled.

GroupCreationFailureReasonConnectionCancelled
Obsolete.

P2p group creation failed because the connection has been cancelled.

GroupCreationFailureReasonGroupRemoved
Obsolete.

P2p group creation failed because the group has been removed.

GroupCreationFailureReasonInvitationFailed
Obsolete.

P2p group creation failed because invitation has failed.

GroupCreationFailureReasonProvisionDiscoveryFailed
Obsolete.

P2p group creation failed because provision discovery has failed.

GroupCreationFailureReasonTimedOut
Obsolete.

P2p group creation failed because it has timed out.

GroupCreationFailureReasonUserRejected
Obsolete.

P2p group creation failed because user has rejected.

NoPermission
Obsolete.

Passed with ActionListener#onFailure.

NoServiceRequests
Obsolete.

Passed with ActionListener#onFailure.

P2pUnsupported
Obsolete.

Passed with ActionListener#onFailure.

WifiP2pConnectionChangedAction

Broadcast intent action indicating that the state of Wi-Fi p2p connectivity has changed.

WifiP2pDiscoveryChangedAction

Broadcast intent action indicating that peer discovery has either started or stopped.

WifiP2pDiscoveryStarted

p2p discovery has started

WifiP2pDiscoveryStopped

p2p discovery has stopped

WifiP2pListenStarted
Obsolete.

p2p listen has started

WifiP2pListenStopped
Obsolete.

p2p listen has stopped

WifiP2pPeersChangedAction

Broadcast intent action indicating that the available peer list has changed.

WifiP2pScanFull
Obsolete.

Run P2P scan on all channels.

WifiP2pScanSingleFreq
Obsolete.

Run P2P scan only on a specific channel.

WifiP2pScanSocial
Obsolete.

Run P2P scan only on social channels.

WifiP2pStateChangedAction

Broadcast intent action to indicate whether Wi-Fi p2p is enabled or disabled.

WifiP2pStateDisabled
Obsolete.

Wi-Fi p2p is disabled.

WifiP2pStateEnabled
Obsolete.

Wi-Fi p2p is enabled.

WifiP2pThisDeviceChangedAction

Broadcast intent action indicating that this device details have changed.

Properties

Name Description
Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsChannelConstrainedDiscoverySupported

Check if this device supports discovery limited to a specific frequency or the social channels.

IsGroupClientRemovalSupported

Check if this device supports removing clients from a group.

IsGroupOwnerIPv6LinkLocalAddressProvided

Checks whether this device, while being a group client, can discover and deliver the group owner's IPv6 link-local address.

IsPccModeSupported

Check if this device supports P2P Connection Compatibility Mode(R1/R2 compatibility mode).

IsSetVendorElementsSupported

Check if this device supports setting vendor elements.

IsWiFiDirectR2Supported

Check if this device supports Wi-Fi Direct R2 (P2P2).

JniIdentityHashCode

Gets the Java identity hash code stored for this peer.

(Inherited from Object)
JniManagedPeerState

Gets the state flags last assigned by the runtime.

(Inherited from JavaObject)
JniPeerMembers

Gets the JNI metadata used to access members of this Java binding.

P2pMaxAllowedVendorElementsLengthBytes

Return the maximum total length (in bytes) of all Vendor specific information elements (VSIEs) which can be set using the #setVendorElements(Channel, List, ActionListener).

PeerReference

Gets the JNI object reference for this Java peer.

(Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Name Description
AddExternalApprover(WifiP2pManager+Channel, MacAddress, WifiP2pManager+IExternalApproverRequestListener)

Set the external approver for a specific peer.

AddLocalService(WifiP2pManager+Channel, WifiP2pServiceInfo, WifiP2pManager+IActionListener)

Register a local service for service discovery.

AddServiceRequest(WifiP2pManager+Channel, WifiP2pServiceRequest, WifiP2pManager+IActionListener)

Add a service discovery request.

CancelConnect(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Cancel any ongoing p2p group negotiation

ClearLocalServices(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Clear all registered local services of service discovery.

ClearServiceRequests(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Clear all registered service discovery requests.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Connect(WifiP2pManager+Channel, WifiP2pConfig, WifiP2pManager+IActionListener)

Start a p2p connection to a device with the specified configuration.

Construct(JniObjectReference, JniObjectReferenceOptions)

Delegates construction of this peer to the runtime's value manager.

(Inherited from JavaObject)
CreateGroup(WifiP2pManager+Channel, WifiP2pConfig, WifiP2pManager+IActionListener)

Create a p2p group with the current device as the group owner.

CreateGroup(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Create a p2p group with the current device as the group owner.

DiscoverPeers(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Initiate peer discovery.

DiscoverPeersOnSocialChannels(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Scan only the social channels.

DiscoverPeersOnSpecificFrequency(WifiP2pManager+Channel, Int32, WifiP2pManager+IActionListener)

Scan only a single channel specified by frequency.

DiscoverServices(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Initiate service discovery.

DiscoverUsdBasedServices(WifiP2pManager+Channel, WifiP2pUsdBasedServiceDiscoveryConfig, WifiP2pManager+IActionListener)

Initiate Un-synchronized service discovery (USD) based service discovery.

Dispose()

Releases the JNI reference held by this managed peer and unregisters the peer from the interop runtime.

(Inherited from Object)
Dispose(Boolean)

Provides a disposal hook for subclasses. This implementation performs no action.

(Inherited from Object)
DisposeUnlessReferenced()

Asks the value manager to dispose this peer unless its mapping retains this same managed instance.

(Inherited from JavaObject)
Equals(Object)

Tests whether another managed peer refers to the same Java object.

(Inherited from JavaObject)
Equals(Object)

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

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetListenState(WifiP2pManager+Channel, IExecutor, IConsumer)

Get p2p listen state.

Initialize(Context, Looper, WifiP2pManager+IChannelListener)

Registers the application with the Wi-Fi framework.

JavaFinalize()
Obsolete.

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

(Inherited from Object)
Notify()

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

(Inherited from Object)
NotifyAll()

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

(Inherited from Object)
RegisterWifiP2pListener(IExecutor, WifiP2pManager+IWifiP2pListener)

Add a listener to listen to Wi-Fi p2p various changes.

RemoveClient(WifiP2pManager+Channel, MacAddress, WifiP2pManager+IActionListener)

Remove the client with the MAC address from the group.

RemoveExternalApprover(WifiP2pManager+Channel, MacAddress, WifiP2pManager+IActionListener)

Remove the external approver for a specific peer.

RemoveGroup(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Remove the current p2p group.

RemoveLocalService(WifiP2pManager+Channel, WifiP2pServiceInfo, WifiP2pManager+IActionListener)

Remove a registered local service added with AddLocalService(WifiP2pManager+Channel, WifiP2pServiceInfo, WifiP2pManager+IActionListener).

RemoveServiceRequest(WifiP2pManager+Channel, WifiP2pServiceRequest, WifiP2pManager+IActionListener)

Remove a specified service discovery request added with AddServiceRequest(WifiP2pManager+Channel, WifiP2pServiceRequest, WifiP2pManager+IActionListener).

RequestConnectionInfo(WifiP2pManager+Channel, WifiP2pManager+IConnectionInfoListener)

Request device connection info.

RequestDeviceInfo(WifiP2pManager+Channel, WifiP2pManager+IDeviceInfoListener)

Request Device Info

RequestDirInfo(WifiP2pManager+Channel, IExecutor, IOutcomeReceiver)

Get the Device Identity Resolution (DIR) Information.

RequestDiscoveryState(WifiP2pManager+Channel, WifiP2pManager+IDiscoveryStateListener)

Request p2p discovery state.

RequestGroupInfo(WifiP2pManager+Channel, WifiP2pManager+IGroupInfoListener)

Request p2p group info.

RequestNetworkInfo(WifiP2pManager+Channel, WifiP2pManager+INetworkInfoListener)

Request network info.

RequestP2pState(WifiP2pManager+Channel, WifiP2pManager+IP2pStateListener)

Request p2p enabled state.

RequestPeers(WifiP2pManager+Channel, WifiP2pManager+IPeerListListener)

Request the current list of peers.

SetConnectionRequestResult(WifiP2pManager+Channel, MacAddress, Int32, String, WifiP2pManager+IActionListener)

Sets the result for an incoming request from a specific peer, with a PIN or password.

SetConnectionRequestResult(WifiP2pManager+Channel, MacAddress, Int32, WifiP2pManager+IActionListener)

Set the result for the incoming request from a specific peer.

SetDnsSdResponseListeners(WifiP2pManager+Channel, WifiP2pManager+IDnsSdServiceResponseListener, WifiP2pManager+IDnsSdTxtRecordListener)

Register a callback to be invoked on receiving Bonjour service discovery response.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetPeerReference(JniObjectReference, JniObjectReferenceOptions)

Stores a reference value in the control block without creating a JNI reference copy.

(Inherited from JavaObject)
SetServiceResponseListener(WifiP2pManager+Channel, WifiP2pManager+IServiceResponseListener)

Register a callback to be invoked on receiving service discovery response.

SetUpnpServiceResponseListener(WifiP2pManager+Channel, WifiP2pManager+IUpnpServiceResponseListener)

Register a callback to be invoked on receiving upnp service discovery response.

SetVendorElements(WifiP2pManager+Channel, IList<ScanResult.InformationElement>, WifiP2pManager+IActionListener)

Set/Clear vendor specific information elements (VSIEs) to be published during Wi-Fi Direct (P2P) discovery.

SetWfdInfo(WifiP2pManager+Channel, WifiP2pWfdInfo, WifiP2pManager+IActionListener)

Set Wifi Display information.

StartListening(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Force p2p to enter listen state.

StartPeerDiscovery(WifiP2pManager+Channel, WifiP2pDiscoveryConfig, WifiP2pManager+IActionListener)

Initiate peer discovery.

StartUsdBasedLocalServiceAdvertisement(WifiP2pManager+Channel, WifiP2pServiceInfo, WifiP2pUsdBasedLocalServiceAdvertisementConfig, WifiP2pManager+IActionListener)

Start a service discovery advertisement using Un-synchronized service discovery (USD).

StopListening(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Force p2p to exit listen state.

StopPeerDiscovery(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Stop an ongoing peer discovery

ToArray<T>()

Creates a managed array from this Java array wrapper.

(Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime()

Unregisters this Java peer from the interop runtime.

(Inherited from Object)
UnregisterWifiP2pListener(WifiP2pManager+IWifiP2pListener)

Remove a listener added using RegisterWifiP2pListener(IExecutor, WifiP2pManager+IWifiP2pListener).

ValidateDirInfo(WifiP2pManager+Channel, WifiP2pDirInfo, IExecutor, IOutcomeReceiver)

Validate the Device Identity Resolution (DIR) Information of a P2P device.

Wait()

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

(Inherited from Object)
Wait(Int64, Int32)

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.

(Inherited from Object)
Wait(Int64)

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.

(Inherited from Object)

Explicit Interface Implementations

Name Description
IJavaPeerable.Disposed()

Marks this peer as disposed and calls Dispose with disposing set to true.

(Inherited from JavaObject)
IJavaPeerable.Finalized()

Marks this peer as disposed and calls Dispose with disposing set to false.

(Inherited from JavaObject)
IJavaPeerable.JniObjectReferenceControlBlock

Gets the native control-block pointer used by this peer.

(Inherited from JavaObject)
IJavaPeerable.SetJniIdentityHashCode(Int32)

Stores the identity hash code supplied by the runtime.

(Inherited from JavaObject)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

Replaces the stored managed peer state flags.

(Inherited from JavaObject)
IJavaPeerable.SetPeerReference(JniObjectReference)

Updates the peer reference and releases a disposed peer's control block when the reference is invalid.

(Inherited from JavaObject)

Extension Methods

Name Description
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)

Reuses a compatible managed peer or obtains a wrapper of the requested type.

TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to