# Print output for @column tags ?> WifiP2pManager - Android SDK | Android Developers

Most visited

Recently visited

WifiP2pManager

public class WifiP2pManager
extends Object

java.lang.Object
   ↳ android.net.wifi.p2p.WifiP2pManager


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(Context, Looper, WifiP2pManager.ChannelListener) 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(WifiP2pManager.Channel, WifiP2pManager.ActionListener). 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(WifiP2pManager.Channel, WifiP2pManager.ActionListener). 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(WifiP2pManager.Channel, WifiP2pManager.PeerListListener). 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(WifiP2pManager.Channel, WifiP2pConfig, WifiP2pManager.ActionListener). 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(WifiP2pManager.Channel, WifiP2pConfig, WifiP2pManager.ActionListener) which creates an access point whose details can be fetched with requestGroupInfo(WifiP2pManager.Channel, WifiP2pManager.GroupInfoListener).

After a successful group formation through createGroup(WifiP2pManager.Channel, WifiP2pConfig, WifiP2pManager.ActionListener) or through connect(WifiP2pManager.Channel, WifiP2pConfig, WifiP2pManager.ActionListener), use requestConnectionInfo(WifiP2pManager.Channel, WifiP2pManager.ConnectionInfoListener) 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(WifiP2pManager.Channel, WifiP2pManager.ActionListener), 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(WifiP2pManager.Channel, WifiP2pServiceInfo, WifiP2pManager.ActionListener). 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(WifiP2pManager.Channel, WifiP2pServiceInfo, WifiP2pManager.ActionListener) removes a local service and clearLocalServices(WifiP2pManager.Channel, WifiP2pManager.ActionListener) 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(WifiP2pManager.Channel, WifiP2pManager.ActionListener). Prior to initiating the discovery, application can add service discovery request with a call to addServiceRequest(WifiP2pManager.Channel, WifiP2pServiceRequest, WifiP2pManager.ActionListener), remove a service discovery request with a call to removeServiceRequest(WifiP2pManager.Channel, WifiP2pServiceRequest, WifiP2pManager.ActionListener) or clear all requests with a call to clearServiceRequests(WifiP2pManager.Channel, WifiP2pManager.ActionListener). 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(WifiP2pManager.Channel, WifiP2pManager.DnsSdServiceResponseListener, WifiP2pManager.DnsSdTxtRecordListener) for Bonjour or setUpnpServiceResponseListener(WifiP2pManager.Channel, WifiP2pManager.UpnpServiceResponseListener) for Upnp.

Note: Registering an application handler with initialize(Context, Looper, WifiP2pManager.ChannelListener) requires the permissions Manifest.permission.ACCESS_WIFI_STATE and Manifest.permission.CHANGE_WIFI_STATE to perform any further peer-to-peer operations.

See also:

Summary

Nested classes

interface WifiP2pManager.ActionListener

Interface for callback invocation on an application action 

class WifiP2pManager.Channel

A channel that connects the application to the Wifi p2p framework. 

interface WifiP2pManager.ChannelListener

Interface for callback invocation when framework channel is lost 

interface WifiP2pManager.ConnectionInfoListener

Interface for callback invocation when connection info is available 

interface WifiP2pManager.DeviceInfoListener

Interface for callback invocation when WifiP2pDevice is available in response to WifiP2pManager.requestDeviceInfo(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.DeviceInfoListener)

interface WifiP2pManager.DiscoveryStateListener

Interface for callback invocation when p2p state is available in response to WifiP2pManager.requestDiscoveryState(WifiP2pManager.Channel, WifiP2pManager.DiscoveryStateListener)

interface WifiP2pManager.DnsSdServiceResponseListener

Interface for callback invocation when Bonjour service discovery response is received 

interface WifiP2pManager.DnsSdTxtRecordListener

Interface for callback invocation when Bonjour TXT record is available for a service 

interface WifiP2pManager.GroupInfoListener

Interface for callback invocation when group info is available 

interface WifiP2pManager.NetworkInfoListener

Interface for callback invocation when NetworkInfo is available in response to WifiP2pManager.requestNetworkInfo(WifiP2pManager.Channel, WifiP2pManager.NetworkInfoListener)

interface WifiP2pManager.P2pStateListener

Interface for callback invocation when p2p state is available in response to WifiP2pManager.requestP2pState(WifiP2pManager.Channel, WifiP2pManager.P2pStateListener)

interface WifiP2pManager.PeerListListener

Interface for callback invocation when peer list is available 

interface WifiP2pManager.ServiceResponseListener

Interface for callback invocation when service discovery response other than Upnp or Bonjour is received 

interface WifiP2pManager.UpnpServiceResponseListener

Interface for callback invocation when upnp service discovery response is received 

Constants

int BUSY

Passed with ActionListener#onFailure.

int ERROR

Passed with ActionListener#onFailure.

String EXTRA_DISCOVERY_STATE

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

String EXTRA_NETWORK_INFO

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

String EXTRA_P2P_DEVICE_LIST

The lookup key for a WifiP2pDeviceList object representing the new peer list when WIFI_P2P_PEERS_CHANGED_ACTION broadcast is sent.

String EXTRA_WIFI_P2P_DEVICE

The lookup key for a WifiP2pDevice object Retrieve with Intent.getParcelableExtra(String).

String EXTRA_WIFI_P2P_GROUP

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

String EXTRA_WIFI_P2P_INFO

The lookup key for a WifiP2pInfo object Retrieve with Intent.getParcelableExtra(String).

String EXTRA_WIFI_STATE

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

int NO_SERVICE_REQUESTS

Passed with ActionListener#onFailure.

int P2P_UNSUPPORTED

Passed with ActionListener#onFailure.

String WIFI_P2P_CONNECTION_CHANGED_ACTION

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

String WIFI_P2P_DISCOVERY_CHANGED_ACTION

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

int WIFI_P2P_DISCOVERY_STARTED

p2p discovery has started

int WIFI_P2P_DISCOVERY_STOPPED

p2p discovery has stopped

String WIFI_P2P_PEERS_CHANGED_ACTION

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

String WIFI_P2P_STATE_CHANGED_ACTION

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

int WIFI_P2P_STATE_DISABLED

Wi-Fi p2p is disabled.

int WIFI_P2P_STATE_ENABLED

Wi-Fi p2p is enabled.

String WIFI_P2P_THIS_DEVICE_CHANGED_ACTION

Broadcast intent action indicating that this device details have changed.

Public methods

void addLocalService(WifiP2pManager.Channel c, WifiP2pServiceInfo servInfo, WifiP2pManager.ActionListener listener)

Register a local service for service discovery.

void addServiceRequest(WifiP2pManager.Channel c, WifiP2pServiceRequest req, WifiP2pManager.ActionListener listener)

Add a service discovery request.

void cancelConnect(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)

Cancel any ongoing p2p group negotiation

The function call immediately returns after sending a connection cancellation request to the framework.

void clearLocalServices(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)

Clear all registered local services of service discovery.

void clearServiceRequests(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)

Clear all registered service discovery requests.

void connect(WifiP2pManager.Channel c, WifiP2pConfig config, WifiP2pManager.ActionListener listener)

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

void createGroup(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)

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

void createGroup(WifiP2pManager.Channel c, WifiP2pConfig config, WifiP2pManager.ActionListener listener)

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

void discoverPeers(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)

Initiate peer discovery.

void discoverServices(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)

Initiate service discovery.

WifiP2pManager.Channel initialize(Context srcContext, Looper srcLooper, WifiP2pManager.ChannelListener listener)

Registers the application with the Wi-Fi framework.

void removeGroup(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)

Remove the current p2p group.

void removeLocalService(WifiP2pManager.Channel c, WifiP2pServiceInfo servInfo, WifiP2pManager.ActionListener listener)

Remove a registered local service added with addLocalService(WifiP2pManager.Channel, WifiP2pServiceInfo, WifiP2pManager.ActionListener)

The function call immediately returns after sending a request to remove a local service to the framework.

void removeServiceRequest(WifiP2pManager.Channel c, WifiP2pServiceRequest req, WifiP2pManager.ActionListener listener)

Remove a specified service discovery request added with addServiceRequest(WifiP2pManager.Channel, WifiP2pServiceRequest, WifiP2pManager.ActionListener)

The function call immediately returns after sending a request to remove service discovery request to the framework.

void requestConnectionInfo(WifiP2pManager.Channel c, WifiP2pManager.ConnectionInfoListener listener)

Request device connection info.

void requestDeviceInfo(WifiP2pManager.Channel c, WifiP2pManager.DeviceInfoListener listener)

Request Device Info

This method provides the device info in the form of a WifiP2pDevice.

void requestDiscoveryState(WifiP2pManager.Channel c, WifiP2pManager.DiscoveryStateListener listener)

Request p2p discovery state.

void requestGroupInfo(WifiP2pManager.Channel c, WifiP2pManager.GroupInfoListener listener)

Request p2p group info.

void requestNetworkInfo(WifiP2pManager.Channel c, WifiP2pManager.NetworkInfoListener listener)

Request network info.

void requestP2pState(WifiP2pManager.Channel c, WifiP2pManager.P2pStateListener listener)

Request p2p enabled state.

void requestPeers(WifiP2pManager.Channel c, WifiP2pManager.PeerListListener listener)

Request the current list of peers.

void setDnsSdResponseListeners(WifiP2pManager.Channel c, WifiP2pManager.DnsSdServiceResponseListener servListener, WifiP2pManager.DnsSdTxtRecordListener txtListener)

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

void setServiceResponseListener(WifiP2pManager.Channel c, WifiP2pManager.ServiceResponseListener listener)

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

void setUpnpServiceResponseListener(WifiP2pManager.Channel c, WifiP2pManager.UpnpServiceResponseListener listener)

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

void stopPeerDiscovery(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)

Stop an ongoing peer discovery

The function call immediately returns after sending a stop request to the framework.

Inherited methods

Constants

BUSY

public static final int BUSY

Passed with ActionListener#onFailure. Indicates that the operation failed because the framework is busy and unable to service the request

Constant Value: 2 (0x00000002)

ERROR

public static final int ERROR

Passed with ActionListener#onFailure. Indicates that the operation failed due to an internal error.

Constant Value: 0 (0x00000000)

EXTRA_DISCOVERY_STATE

public static final String EXTRA_DISCOVERY_STATE

The lookup key for an int that indicates whether p2p discovery has started or stopped. Retrieve it with Intent.getIntExtra(String, int).

See also:

Constant Value: "discoveryState"

EXTRA_NETWORK_INFO

public static final String EXTRA_NETWORK_INFO

The lookup key for a NetworkInfo object associated with the p2p network. Retrieve with Intent.getParcelableExtra(String).

Constant Value: "networkInfo"

EXTRA_P2P_DEVICE_LIST

public static final String EXTRA_P2P_DEVICE_LIST

The lookup key for a WifiP2pDeviceList object representing the new peer list when WIFI_P2P_PEERS_CHANGED_ACTION broadcast is sent.

Retrieve with Intent.getParcelableExtra(String).

Constant Value: "wifiP2pDeviceList"

EXTRA_WIFI_P2P_DEVICE

public static final String EXTRA_WIFI_P2P_DEVICE

The lookup key for a WifiP2pDevice object Retrieve with Intent.getParcelableExtra(String).

Constant Value: "wifiP2pDevice"

EXTRA_WIFI_P2P_GROUP

public static final String EXTRA_WIFI_P2P_GROUP

The lookup key for a WifiP2pGroup object associated with the p2p network. Retrieve with Intent.getParcelableExtra(String).

Constant Value: "p2pGroupInfo"

EXTRA_WIFI_P2P_INFO

public static final String EXTRA_WIFI_P2P_INFO

The lookup key for a WifiP2pInfo object Retrieve with Intent.getParcelableExtra(String).

Constant Value: "wifiP2pInfo"

EXTRA_WIFI_STATE

public static final String EXTRA_WIFI_STATE

The lookup key for an int that indicates whether Wi-Fi p2p is enabled or disabled. Retrieve it with Intent.getIntExtra(String, int).

See also:

Constant Value: "wifi_p2p_state"

NO_SERVICE_REQUESTS

public static final int NO_SERVICE_REQUESTS

Passed with ActionListener#onFailure. Indicates that the discoverServices(WifiP2pManager.Channel, WifiP2pManager.ActionListener) failed because no service requests are added. Use addServiceRequest(WifiP2pManager.Channel, WifiP2pServiceRequest, WifiP2pManager.ActionListener) to add a service request.

Constant Value: 3 (0x00000003)

P2P_UNSUPPORTED

public static final int P2P_UNSUPPORTED

Passed with ActionListener#onFailure. Indicates that the operation failed because p2p is unsupported on the device.

Constant Value: 1 (0x00000001)

WIFI_P2P_CONNECTION_CHANGED_ACTION

public static final String WIFI_P2P_CONNECTION_CHANGED_ACTION

Broadcast intent action indicating that the state of Wi-Fi p2p connectivity has changed. One extra EXTRA_WIFI_P2P_INFO provides the p2p connection info in the form of a WifiP2pInfo object. Another extra EXTRA_NETWORK_INFO provides the network info in the form of a NetworkInfo. A third extra provides the details of the group and may contain a null. All of these permissions are required to receive this broadcast: Manifest.permission.ACCESS_FINE_LOCATION and Manifest.permission.ACCESS_WIFI_STATE

See also:

Constant Value: "android.net.wifi.p2p.CONNECTION_STATE_CHANGE"

WIFI_P2P_DISCOVERY_CHANGED_ACTION

public static final String WIFI_P2P_DISCOVERY_CHANGED_ACTION

Broadcast intent action indicating that peer discovery has either started or stopped. One extra EXTRA_DISCOVERY_STATE indicates whether discovery has started or stopped.

Note that discovery will be stopped during a connection setup. If the application tries to re-initiate discovery during this time, it can fail.

Constant Value: "android.net.wifi.p2p.DISCOVERY_STATE_CHANGE"

WIFI_P2P_DISCOVERY_STARTED

public static final int WIFI_P2P_DISCOVERY_STARTED

p2p discovery has started

See also:

Constant Value: 2 (0x00000002)

WIFI_P2P_DISCOVERY_STOPPED

public static final int WIFI_P2P_DISCOVERY_STOPPED

p2p discovery has stopped

See also:

Constant Value: 1 (0x00000001)

WIFI_P2P_PEERS_CHANGED_ACTION

public static final String WIFI_P2P_PEERS_CHANGED_ACTION

Broadcast intent action indicating that the available peer list has changed. This can be sent as a result of peers being found, lost or updated. All of these permissions are required to receive this broadcast: Manifest.permission.ACCESS_FINE_LOCATION and Manifest.permission.ACCESS_WIFI_STATE

An extra EXTRA_P2P_DEVICE_LIST provides the full list of current peers. The full list of peers can also be obtained any time with requestPeers(WifiP2pManager.Channel, WifiP2pManager.PeerListListener).

See also:

Constant Value: "android.net.wifi.p2p.PEERS_CHANGED"

WIFI_P2P_STATE_CHANGED_ACTION

public static final String WIFI_P2P_STATE_CHANGED_ACTION

Broadcast intent action to indicate whether Wi-Fi p2p is enabled or disabled. An extra EXTRA_WIFI_STATE provides the state information as int.

See also:

Constant Value: "android.net.wifi.p2p.STATE_CHANGED"

WIFI_P2P_STATE_DISABLED

public static final int WIFI_P2P_STATE_DISABLED

Wi-Fi p2p is disabled.

See also:

Constant Value: 1 (0x00000001)

WIFI_P2P_STATE_ENABLED

public static final int WIFI_P2P_STATE_ENABLED

Wi-Fi p2p is enabled.

See also:

Constant Value: 2 (0x00000002)

WIFI_P2P_THIS_DEVICE_CHANGED_ACTION

public static final String WIFI_P2P_THIS_DEVICE_CHANGED_ACTION

Broadcast intent action indicating that this device details have changed.

An extra EXTRA_WIFI_P2P_DEVICE provides this device details. The valid device details can also be obtained with requestDeviceInfo(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.DeviceInfoListener) when p2p is enabled. To get information notifications on P2P getting enabled refers WIFI_P2P_STATE_ENABLED.

The EXTRA_WIFI_P2P_DEVICE extra contains an anonymized version of the device's MAC address. Callers holding the android.Manifest.permission#LOCAL_MAC_ADDRESS permission can use requestDeviceInfo(WifiP2pManager.Channel, WifiP2pManager.DeviceInfoListener) to obtain the actual MAC address of this device. All of these permissions are required to receive this broadcast: Manifest.permission.ACCESS_FINE_LOCATION and Manifest.permission.ACCESS_WIFI_STATE

See also:

Constant Value: "android.net.wifi.p2p.THIS_DEVICE_CHANGED"

Public methods

addLocalService

public void addLocalService (WifiP2pManager.Channel c, 
                WifiP2pServiceInfo servInfo, 
                WifiP2pManager.ActionListener listener)

Register a local service for service discovery. If a local service is registered, the framework automatically responds to a service discovery request from a peer.

The function call immediately returns after sending a request to add a local service to the framework. The application is notified of a success or failure to add service through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

The service information is set through WifiP2pServiceInfo.
or its subclass calls WifiP2pUpnpServiceInfo#newInstance or WifiP2pDnsSdServiceInfo#newInstance for a Upnp or Bonjour service respectively

The service information can be cleared with calls to removeLocalService(WifiP2pManager.Channel, WifiP2pServiceInfo, WifiP2pManager.ActionListener) or clearLocalServices(WifiP2pManager.Channel, WifiP2pManager.ActionListener).
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

servInfo WifiP2pServiceInfo: is a local service information.

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

addServiceRequest

public void addServiceRequest (WifiP2pManager.Channel c, 
                WifiP2pServiceRequest req, 
                WifiP2pManager.ActionListener listener)

Add a service discovery request.

The function call immediately returns after sending a request to add service discovery request to the framework. The application is notified of a success or failure to add service through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

After service discovery request is added, you can initiate service discovery by discoverServices(WifiP2pManager.Channel, WifiP2pManager.ActionListener).

The added service requests can be cleared with calls to removeServiceRequest(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.nsd.WifiP2pServiceRequest, android.net.wifi.p2p.WifiP2pManager.ActionListener) or clearServiceRequests(android.net.wifi.p2p.WifiP2pManager.Channel, android.net.wifi.p2p.WifiP2pManager.ActionListener).

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

req WifiP2pServiceRequest: is the service discovery request.

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

cancelConnect

public void cancelConnect (WifiP2pManager.Channel c, 
                WifiP2pManager.ActionListener listener)

Cancel any ongoing p2p group negotiation

The function call immediately returns after sending a connection cancellation request to the framework. The application is notified of a success or failure to initiate cancellation through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

clearLocalServices

public void clearLocalServices (WifiP2pManager.Channel c, 
                WifiP2pManager.ActionListener listener)

Clear all registered local services of service discovery.

The function call immediately returns after sending a request to clear all local services to the framework. The application is notified of a success or failure to add service through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

clearServiceRequests

public void clearServiceRequests (WifiP2pManager.Channel c, 
                WifiP2pManager.ActionListener listener)

Clear all registered service discovery requests.

The function call immediately returns after sending a request to clear all service discovery requests to the framework. The application is notified of a success or failure to add service through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

connect

public void connect (WifiP2pManager.Channel c, 
                WifiP2pConfig config, 
                WifiP2pManager.ActionListener listener)

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

The function call immediately returns after sending a connection request to the framework. The application is notified of a success or failure to initiate connect through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Register for WIFI_P2P_CONNECTION_CHANGED_ACTION intent to determine when the framework notifies of a change in connectivity.

If the current device is not part of a p2p group, a connect request initiates a group negotiation with the peer.

If the current device is part of an existing p2p group or has created a p2p group with createGroup(WifiP2pManager.Channel, WifiP2pConfig, WifiP2pManager.ActionListener), an invitation to join the group is sent to the peer device.
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

config WifiP2pConfig: options as described in WifiP2pConfig class

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

createGroup

public void createGroup (WifiP2pManager.Channel c, 
                WifiP2pManager.ActionListener listener)

Create a p2p group with the current device as the group owner. This essentially creates an access point that can accept connections from legacy clients as well as other p2p devices.

Note: This function would normally not be used unless the current device needs to form a p2p connection with a legacy client

The function call immediately returns after sending a group creation request to the framework. The application is notified of a success or failure to initiate group creation through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Application can request for the group details with requestGroupInfo(WifiP2pManager.Channel, WifiP2pManager.GroupInfoListener).
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

createGroup

public void createGroup (WifiP2pManager.Channel c, 
                WifiP2pConfig config, 
                WifiP2pManager.ActionListener listener)

Create a p2p group with the current device as the group owner. This essentially creates an access point that can accept connections from legacy clients as well as other p2p devices.

An app should use WifiP2pConfig.Builder to build the configuration for a group.

Note: This function would normally not be used unless the current device needs to form a p2p group as a Group Owner and allow peers to join it as either Group Clients or legacy Wi-Fi STAs.

The function call immediately returns after sending a group creation request to the framework. The application is notified of a success or failure to initiate group creation through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Application can request for the group details with requestGroupInfo(WifiP2pManager.Channel, WifiP2pManager.GroupInfoListener).
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener). This value cannot be null.

config WifiP2pConfig: the configuration of a p2p group. This value may be null.

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null. This value may be null.

discoverPeers

public void discoverPeers (WifiP2pManager.Channel c, 
                WifiP2pManager.ActionListener listener)

Initiate peer discovery. A discovery process involves scanning for available Wi-Fi peers for the purpose of establishing a connection.

The function call immediately returns after sending a discovery request to the framework. The application is notified of a success or failure to initiate discovery through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

The discovery remains active until a connection is initiated or a p2p group is formed. Register for WIFI_P2P_PEERS_CHANGED_ACTION intent to determine when the framework notifies of a change as peers are discovered.

Upon receiving a WIFI_P2P_PEERS_CHANGED_ACTION intent, an application can request for the list of peers using requestPeers(WifiP2pManager.Channel, WifiP2pManager.PeerListListener).
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

discoverServices

public void discoverServices (WifiP2pManager.Channel c, 
                WifiP2pManager.ActionListener listener)

Initiate service discovery. A discovery process involves scanning for requested services for the purpose of establishing a connection to a peer that supports an available service.

The function call immediately returns after sending a request to start service discovery to the framework. The application is notified of a success or failure to initiate discovery through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

The services to be discovered are specified with calls to addServiceRequest(WifiP2pManager.Channel, WifiP2pServiceRequest, WifiP2pManager.ActionListener).

The application is notified of the response against the service discovery request through listener callbacks registered by setServiceResponseListener(WifiP2pManager.Channel, WifiP2pManager.ServiceResponseListener) or setDnsSdResponseListeners(WifiP2pManager.Channel, WifiP2pManager.DnsSdServiceResponseListener, WifiP2pManager.DnsSdTxtRecordListener), or setUpnpServiceResponseListener(WifiP2pManager.Channel, WifiP2pManager.UpnpServiceResponseListener).
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

initialize

public WifiP2pManager.Channel initialize (Context srcContext, 
                Looper srcLooper, 
                WifiP2pManager.ChannelListener listener)

Registers the application with the Wi-Fi framework. This function must be the first to be called before any p2p operations are performed.

Parameters
srcContext Context: is the context of the source

srcLooper Looper: is the Looper on which the callbacks are receivied

listener WifiP2pManager.ChannelListener: for callback at loss of framework communication. Can be null.

Returns
WifiP2pManager.Channel Channel instance that is necessary for performing any further p2p operations

removeGroup

public void removeGroup (WifiP2pManager.Channel c, 
                WifiP2pManager.ActionListener listener)

Remove the current p2p group.

The function call immediately returns after sending a group removal request to the framework. The application is notified of a success or failure to initiate group removal through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

removeLocalService

public void removeLocalService (WifiP2pManager.Channel c, 
                WifiP2pServiceInfo servInfo, 
                WifiP2pManager.ActionListener listener)

Remove a registered local service added with addLocalService(WifiP2pManager.Channel, WifiP2pServiceInfo, WifiP2pManager.ActionListener)

The function call immediately returns after sending a request to remove a local service to the framework. The application is notified of a success or failure to add service through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

servInfo WifiP2pServiceInfo: is the local service information.

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

removeServiceRequest

public void removeServiceRequest (WifiP2pManager.Channel c, 
                WifiP2pServiceRequest req, 
                WifiP2pManager.ActionListener listener)

Remove a specified service discovery request added with addServiceRequest(WifiP2pManager.Channel, WifiP2pServiceRequest, WifiP2pManager.ActionListener)

The function call immediately returns after sending a request to remove service discovery request to the framework. The application is notified of a success or failure to add service through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

req WifiP2pServiceRequest: is the service discovery request.

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.

requestConnectionInfo

public void requestConnectionInfo (WifiP2pManager.Channel c, 
                WifiP2pManager.ConnectionInfoListener listener)

Request device connection info.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ConnectionInfoListener: for callback when connection info is available. Can be null.

requestDeviceInfo

public void requestDeviceInfo (WifiP2pManager.Channel c, 
                WifiP2pManager.DeviceInfoListener listener)

Request Device Info

This method provides the device info in the form of a WifiP2pDevice. Valid WifiP2pDevice is returned when p2p is enabled. To get information notifications on P2P getting enabled refers WIFI_P2P_STATE_ENABLED.

This WifiP2pDevice is returned using the DeviceInfoListener listener.

WifiP2pDevice.deviceAddress is only available if the caller holds the android.Manifest.permission#LOCAL_MAC_ADDRESS permission, and holds the anonymized MAC address (02:00:00:00:00:00) otherwise.

This information is also included in the WIFI_P2P_THIS_DEVICE_CHANGED_ACTION broadcast event with extra EXTRA_WIFI_P2P_DEVICE.
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(android.content.Context, android.os.Looper, android.net.wifi.p2p.WifiP2pManager.ChannelListener). This value cannot be null.

listener WifiP2pManager.DeviceInfoListener: for callback when network info is available. This value cannot be null.

requestDiscoveryState

public void requestDiscoveryState (WifiP2pManager.Channel c, 
                WifiP2pManager.DiscoveryStateListener listener)

Request p2p discovery state.

This state indicates whether p2p discovery has started or stopped. The valid value is one of WIFI_P2P_DISCOVERY_STARTED or WIFI_P2P_DISCOVERY_STOPPED. The state is returned using the DiscoveryStateListener listener.

This state is also included in the WIFI_P2P_DISCOVERY_CHANGED_ACTION broadcast event with extra EXTRA_DISCOVERY_STATE.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener). This value cannot be null.

listener WifiP2pManager.DiscoveryStateListener: for callback when discovery state is available.. This value cannot be null.

requestGroupInfo

public void requestGroupInfo (WifiP2pManager.Channel c, 
                WifiP2pManager.GroupInfoListener listener)

Request p2p group info.
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.GroupInfoListener: for callback when group info is available. Can be null.

requestNetworkInfo

public void requestNetworkInfo (WifiP2pManager.Channel c, 
                WifiP2pManager.NetworkInfoListener listener)

Request network info.

This method provides the network info in the form of a NetworkInfo. NetworkInfo.isAvailable() indicates the p2p availability and NetworkInfo.getDetailedState() reports the current fine-grained state of the network. This NetworkInfo is returned using the NetworkInfoListener listener.

This information is also included in the WIFI_P2P_CONNECTION_CHANGED_ACTION broadcast event with extra EXTRA_NETWORK_INFO.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener). This value cannot be null.

listener WifiP2pManager.NetworkInfoListener: for callback when network info is available.. This value cannot be null.

requestP2pState

public void requestP2pState (WifiP2pManager.Channel c, 
                WifiP2pManager.P2pStateListener listener)

Request p2p enabled state.

This state indicates whether Wi-Fi p2p is enabled or disabled. The valid value is one of WIFI_P2P_STATE_DISABLED or WIFI_P2P_STATE_ENABLED. The state is returned using the P2pStateListener listener.

This state is also included in the WIFI_P2P_STATE_CHANGED_ACTION broadcast event with extra EXTRA_WIFI_STATE.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener). This value cannot be null.

listener WifiP2pManager.P2pStateListener: for callback when p2p state is available.. This value cannot be null.

requestPeers

public void requestPeers (WifiP2pManager.Channel c, 
                WifiP2pManager.PeerListListener listener)

Request the current list of peers.
Requires Manifest.permission.ACCESS_FINE_LOCATION

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.PeerListListener: for callback when peer list is available. Can be null.

setDnsSdResponseListeners

public void setDnsSdResponseListeners (WifiP2pManager.Channel c, 
                WifiP2pManager.DnsSdServiceResponseListener servListener, 
                WifiP2pManager.DnsSdTxtRecordListener txtListener)

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

see discoverServices(WifiP2pManager.Channel, WifiP2pManager.ActionListener) for the detail.

Parameters
servListener WifiP2pManager.DnsSdServiceResponseListener: is for listening to a Bonjour service response

txtListener WifiP2pManager.DnsSdTxtRecordListener: is for listening to a Bonjour TXT record response

setServiceResponseListener

public void setServiceResponseListener (WifiP2pManager.Channel c, 
                WifiP2pManager.ServiceResponseListener listener)

Register a callback to be invoked on receiving service discovery response. Used only for vendor specific protocol right now. For Bonjour or Upnp, use setDnsSdResponseListeners(WifiP2pManager.Channel, WifiP2pManager.DnsSdServiceResponseListener, WifiP2pManager.DnsSdTxtRecordListener) or setUpnpServiceResponseListener(WifiP2pManager.Channel, WifiP2pManager.UpnpServiceResponseListener) respectively.

see discoverServices(WifiP2pManager.Channel, WifiP2pManager.ActionListener) for the detail.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ServiceResponseListener: for callbacks on receiving service discovery response.

setUpnpServiceResponseListener

public void setUpnpServiceResponseListener (WifiP2pManager.Channel c, 
                WifiP2pManager.UpnpServiceResponseListener listener)

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

see discoverServices(WifiP2pManager.Channel, WifiP2pManager.ActionListener) for the detail.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.UpnpServiceResponseListener: for callbacks on receiving service discovery response.

stopPeerDiscovery

public void stopPeerDiscovery (WifiP2pManager.Channel c, 
                WifiP2pManager.ActionListener listener)

Stop an ongoing peer discovery

The function call immediately returns after sending a stop request to the framework. The application is notified of a success or failure to initiate stop through listener callbacks ActionListener#onSuccess or ActionListener#onFailure.

Parameters
c WifiP2pManager.Channel: is the channel created at initialize(Context, Looper, WifiP2pManager.ChannelListener)

listener WifiP2pManager.ActionListener: for callbacks on success or failure. Can be null.