Added in API level 14

android.net.wifi.p2p


Provides classes to create peer-to-peer (P2P) connections with Wi-Fi Direct.

Using these APIs, you can discover and connect to other devices when each device supports Wi-Fi Direct, then communicate over a speedy connection across distances much longer than a Bluetooth connection. The primary class you need to work with is WifiP2pManager, which you can acquire by calling getSystemService(WIFI_P2P_SERVICE). The WifiP2pManager includes APIs that allow you to:

Several other interfaces and classes are necessary as well, such as:

  • The WifiP2pManager.ActionListener interface allows you to receive callbacks when an operation such as discovering peers or connecting to them succeeds or fails.
  • WifiP2pManager.PeerListListener interface allows you to receive information about discovered peers. The callback provides a WifiP2pDeviceList, from which you can retrieve a WifiP2pDevice object for each device within range and get information such as the device name, address, device type, the WPS configurations the device supports, and more.
  • The WifiP2pManager.GroupInfoListener interface allows you to receive information about a P2P group. The callback provides a WifiP2pGroup object, which provides group information such as the owner, the network name, and passphrase.
  • WifiP2pManager.ConnectionInfoListener interface allows you to receive information about the current connection. The callback provides a WifiP2pInfo object, which has information such as whether a group has been formed and who is the group owner.

In order to use the Wi-Fi P2P APIs, your app must request the following user permissions:

For example code, see the Wi-Fi Direct Demo sample application.

Note: Not all Android-powered devices support Wi-Fi Direct. If your application uses Wi-Fi Direct, declare so with a <uses-feature> element in the manifest file:

 <manifest ...>
     <uses-feature android:name="android.hardware.wifi.direct" />
     ...
 </manifest>
 

Interfaces

WifiP2pManager.ActionListener Interface for callback invocation on an application action 
WifiP2pManager.ChannelListener Interface for callback invocation when framework channel is lost 
WifiP2pManager.ConnectionInfoListener Interface for callback invocation when connection info is available 
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)
WifiP2pManager.DiscoveryStateListener Interface for callback invocation when p2p state is available in response to WifiP2pManager.requestDiscoveryState(Channel, DiscoveryStateListener)
WifiP2pManager.DnsSdServiceResponseListener Interface for callback invocation when Bonjour service discovery response is received 
WifiP2pManager.DnsSdTxtRecordListener Interface for callback invocation when Bonjour TXT record is available for a service 
WifiP2pManager.ExternalApproverRequestListener Interface for callback invocation when an incoming request is received. 
WifiP2pManager.GroupInfoListener Interface for callback invocation when group info is available 
WifiP2pManager.NetworkInfoListener Interface for callback invocation when NetworkInfo is available in response to WifiP2pManager.requestNetworkInfo(Channel, NetworkInfoListener)
WifiP2pManager.P2pStateListener Interface for callback invocation when p2p state is available in response to WifiP2pManager.requestP2pState(Channel, P2pStateListener)
WifiP2pManager.PeerListListener Interface for callback invocation when peer list is available 
WifiP2pManager.ServiceResponseListener Interface for callback invocation when service discovery response other than Upnp or Bonjour is received 
WifiP2pManager.UpnpServiceResponseListener Interface for callback invocation when upnp service discovery response is received 
WifiP2pManager.WifiP2pListener Interface used to listen to Wi-Fi p2p various changes such as device state change, discovery started/stopped, connection change, etc. 

Classes

WifiP2pConfig A class representing a Wi-Fi P2p configuration for setting up a connection  
WifiP2pConfig.Builder Builder used to build WifiP2pConfig objects for creating or joining a group. 
WifiP2pDevice A class representing a Wi-Fi p2p device Note that the operations are not thread safe  
WifiP2pDeviceList A class representing a Wi-Fi P2p device list. 
WifiP2pDiscoveryConfig A class representing a Wi-Fi P2P scan configuration for setting up discovery. 
WifiP2pDiscoveryConfig.Builder Builder for WifiP2pDiscoveryConfig
WifiP2pGroup A class representing a Wi-Fi P2p group. 
WifiP2pInfo A class representing connection information about a Wi-Fi p2p group  
WifiP2pManager This class provides the API for managing Wi-Fi peer-to-peer connectivity. 
WifiP2pManager.Channel A channel that connects the application to the Wifi p2p framework. 
WifiP2pPairingBootstrappingConfig A class representing Wi-Fi Direct pairing bootstrapping config 
WifiP2pUsdBasedLocalServiceAdvertisementConfig A class representing a Wi-Fi P2P USD based service advertisement configuration for advertising the services. 
WifiP2pUsdBasedLocalServiceAdvertisementConfig.Builder Builder for WifiP2pUsdBasedLocalServiceAdvertisementConfig
WifiP2pUsdBasedServiceDiscoveryConfig A class representing a Wi-Fi P2P USD based service discovery configuration for discovering the services. 
WifiP2pUsdBasedServiceDiscoveryConfig.Builder Builder for WifiP2pUsdBasedServiceDiscoveryConfig
WifiP2pWfdInfo A class representing Wifi Display information for a device.