Partager via


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.

<strong>Note:</strong> 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

WifiP2pManager(IntPtr, JniHandleOwnership)

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

Fields

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.

ConnectionRequestDeferShowPinToService
Obsolete.

Defer the 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.

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

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.

IsSetVendorElementsSupported

Check if this device supports setting vendor elements.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
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 (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

AddExternalApprover(WifiP2pManager+Channel, MacAddress, WifiP2pManager+IExternalApproverRequestListener)
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.

CreateGroup(WifiP2pManager+Channel, WifiP2pConfig, WifiP2pManager+IActionListener)
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)
DiscoverPeersOnSpecificFrequency(WifiP2pManager+Channel, Int32, WifiP2pManager+IActionListener)
DiscoverServices(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Initiate service discovery.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
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)
Initialize(Context, Looper, WifiP2pManager+IChannelListener)

Registers the application with the Wi-Fi framework.

JavaFinalize()

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)
RemoveClient(WifiP2pManager+Channel, MacAddress, WifiP2pManager+IActionListener)
RemoveExternalApprover(WifiP2pManager+Channel, MacAddress, WifiP2pManager+IActionListener)
RemoveGroup(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Remove the current p2p group.

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

Remove a registered local service added with M:Android.Net.Wifi.P2p.WifiP2pManager.AddLocalService(.Channel,Android.Net.Wifi.P2p.Nsd.WifiP2pServiceInfo,Android.Net.Wifi.P2p.Nsd.WifiP2pServiceInfo)

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

Request device connection info.

RequestDeviceInfo(WifiP2pManager+Channel, WifiP2pManager+IDeviceInfoListener)
RequestDiscoveryState(WifiP2pManager+Channel, WifiP2pManager+IDiscoveryStateListener)
RequestGroupInfo(WifiP2pManager+Channel, WifiP2pManager+IGroupInfoListener)

Request p2p group info.

RequestNetworkInfo(WifiP2pManager+Channel, WifiP2pManager+INetworkInfoListener)
RequestP2pState(WifiP2pManager+Channel, WifiP2pManager+IP2pStateListener)
RequestPeers(WifiP2pManager+Channel, WifiP2pManager+IPeerListListener)

Request the current list of peers.

SetConnectionRequestResult(WifiP2pManager+Channel, MacAddress, Int32, String, WifiP2pManager+IActionListener)
SetConnectionRequestResult(WifiP2pManager+Channel, MacAddress, Int32, WifiP2pManager+IActionListener)
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)
SetServiceResponseListener(WifiP2pManager+Channel, WifiP2pManager+IServiceResponseListener)
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)
SetWfdInfo(WifiP2pManager+Channel, WifiP2pWfdInfo, WifiP2pManager+IActionListener)
StartListening(WifiP2pManager+Channel, WifiP2pManager+IActionListener)
StartPeerDiscovery(WifiP2pManager+Channel, WifiP2pDiscoveryConfig, WifiP2pManager+IActionListener)
StopListening(WifiP2pManager+Channel, WifiP2pManager+IActionListener)
StopPeerDiscovery(WifiP2pManager+Channel, WifiP2pManager+IActionListener)

Stop an ongoing peer discovery

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
UnregisterWifiP2pListener(WifiP2pManager+IWifiP2pListener)
Wait()

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

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, 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 <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
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.

TryJavaCast<TResult>(IJavaPeerable, TResult)

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

Applies to