WifiP2pManager Class
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.
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
- 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.
WifiP2pConfig
WifiP2pInfo
WifiP2pGroup
WifiP2pDevice
WifiP2pDeviceList
android.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 |
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 |
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 |
ExtraP2pDeviceList |
The lookup key for a |
ExtraRequestConfig |
The lookup key for the |
ExtraRequestResponse |
The lookup key for the result of a request, true if accepted, false otherwise. |
ExtraWifiP2pDevice |
The lookup key for a |
ExtraWifiP2pGroup |
The lookup key for a |
ExtraWifiP2pInfo |
The lookup key for a |
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 |
P2pUnsupported |
Obsolete.
Passed with |
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 |
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
|
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
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 |
JavaAs<TResult>(IJavaPeerable) |
Try to coerce |
TryJavaCast<TResult>(IJavaPeerable, TResult) |
Try to coerce |