All Downloads are FREE. Search and download functionalities are using the official Maven repository.

android.net.wifi.p2p.package.html Maven / Gradle / Ivy

Go to download

A library jar that provides APIs for Applications written for the Google Android Platform.

There is a newer version: 14-robolectric-10818077
Show newest version


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 {@link android.net.wifi.p2p.WifiP2pManager}, which you can acquire by calling {@link android.app.Activity#getSystemService getSystemService(WIFI_P2P_SERVICE)}. The {@link android.net.wifi.p2p.WifiP2pManager} includes APIs that allow you to:

  • Initialize your application for P2P connections by calling {@link android.net.wifi.p2p.WifiP2pManager#initialize initialize()}
  • Discover nearby devices by calling {@link android.net.wifi.p2p.WifiP2pManager#discoverPeers discoverPeers()}
  • Start a P2P connection by calling {@link android.net.wifi.p2p.WifiP2pManager#connect connect()}
  • And more

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

  • The {@link android.net.wifi.p2p.WifiP2pManager.ActionListener} interface allows you to receive callbacks when an operation such as discovering peers or connecting to them succeeds or fails.
  • {@link android.net.wifi.p2p.WifiP2pManager.PeerListListener} interface allows you to receive information about discovered peers. The callback provides a {@link android.net.wifi.p2p.WifiP2pDeviceList}, from which you can retrieve a {@link android.net.wifi.p2p.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 {@link android.net.wifi.p2p.WifiP2pManager.GroupInfoListener} interface allows you to receive information about a P2P group. The callback provides a {@link android.net.wifi.p2p.WifiP2pGroup} object, which provides group information such as the owner, the network name, and passphrase.
  • {@link android.net.wifi.p2p.WifiP2pManager.ConnectionInfoListener} interface allows you to receive information about the current connection. The callback provides a {@link android.net.wifi.p2p.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:

  • {@link android.Manifest.permission#ACCESS_WIFI_STATE}
  • {@link android.Manifest.permission#CHANGE_WIFI_STATE}
  • {@link android.Manifest.permission#INTERNET} (although your app doesn’t technically connect to the Internet, communicating to Wi-Fi Direct peers with standard java sockets requires Internet permission).

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 {@code <uses-feature>} element in the manifest file:

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy