What Wi-Fi Direct is
Wi-Fi Direct is a Wi-Fi Alliance technology that lets devices create their own Wi-Fi network without an internet connection or an access point. The Alliance describes three abilities: devices connect directly to each other, they can form either a one-to-one connection or a group of several devices at once, and a device can see which devices are available and either request a connection or receive an invitation to one.
On Android, apps reach it through the Wi-Fi P2P API. Google’s overview says it lets devices with the right hardware connect over Wi-Fi without an intermediate access point, over a fast connection that reaches much further than a Bluetooth connection. It names multiplayer games and photo sharing as typical uses. For a one-paragraph definition, see What is Wi-Fi Direct?.
Step 1: finding peers
Everything starts with a WifiP2pManager, which an app registers with the Wi-Fi framework before calling anything else. The app also registers a broadcast receiver, because the Wi-Fi P2P framework reports events as system broadcasts: Wi-Fi P2P turning on or off, the peer list changing, the connection state changing, and this device’s details changing.
Discovery is asynchronous. The app calls discoverPeers(), and the success callback only means that discovery started; it says nothing about who was found. When the system finds peers it broadcasts a peers-changed event, and the app calls requestPeers() to get the current list of nearby devices.
Devices can also advertise what they offer. Android’s service discovery guide shows an app registering a local service as a DNS-SD record with key and value pairs, such as a listening port and a display name. Once it is registered, the framework answers discovery requests from peers on the app’s behalf, so a device can pick a peer by the service it runs rather than by name. How do devices discover services without a server or DNS? covers the general idea.
Step 2: choosing a group owner
A Wi-Fi Direct group needs one device to act as the group owner, which plays the role an access point plays in an ordinary Wi-Fi network. Android’s guide says that Wi-Fi Direct looks at each device’s power management, user interface and service capabilities, and picks the device best able to handle the server responsibilities.
An app can influence the choice. The groupOwnerIntent field in WifiP2pConfig is an integer from 0, the least inclination to be group owner, to 15, the most; a separate constant lets the system choose. An app can also skip negotiation and call createGroup(), which makes the current device the group owner. Android’s guide notes this is how a phone hosts a network that includes legacy devices, meaning devices that do not support Wi-Fi Direct at all. WifiP2pConfig can also restrict the group owner to the 2.4 GHz, 5 GHz or 6 GHz band, or leave the band to the system.
Step 3: connecting and moving data
To connect, the app passes the chosen peer’s device address in a WifiP2pConfig to connect(). When the connection state changes, the app calls requestConnectionInfo() and learns three things: whether a group formed, whether this device is the group owner, and the group owner’s IP address.
Android’s guide points out that Wi-Fi Direct supports WPA2 encryption, where some ad hoc networks support only WEP. That protects the radio link between the two devices. It is link-layer protection, not end-to-end encryption, so an app that forwards data onward still needs its own.
From here it is ordinary networking. Android’s example opens a ServerSocket on one device, waits for a client in a background thread, and has the other device open a Socket to the server’s IP address and port, then send bytes as a stream. Because the transfer uses standard sockets, the app declares the INTERNET permission even though no internet is involved.
Permissions changed over time. Apps that target Android 13 (API level 33) and higher need the NEARBY_WIFI_DEVICES permission for discoverPeers() and connect(); apps that target earlier versions need ACCESS_FINE_LOCATION instead. Both are runtime permissions the user grants.
Limits
- Hardware and state. A device must support Wi-Fi P2P, and P2P can be enabled or disabled at any time. Apps check the P2P state broadcast before relying on it.
- Shared radio. Android’s Wi-Fi Aware guide notes that, depending on hardware and firmware, some devices cannot use Wi-Fi Aware while Wi-Fi Direct, SoftAP or tethering is in use. The direct-link features on one phone can get in each other’s way.
- Android first. Wi-Fi Direct is exposed to apps through Android’s P2P API. Apple’s technote on leaving Multipeer Connectivity names two peer-to-peer Wi-Fi options for apps, Apple peer-to-peer Wi-Fi in the Network framework and the industry-standard Wi-Fi Aware, so an iPhone is not a Wi-Fi Direct peer for an Android app. Can an iPhone and an Android phone connect directly without internet? compares the options.
- One group, one hop. The P2P API forms groups and reports who is in them; it has no call that forwards traffic from one group to another. An app that wants to reach devices beyond its own group has to relay messages itself, which is what an application-level mesh between phones does.
Wi-Fi Direct is a good fit for a burst of data between two or a few Android devices that have already found each other. For ongoing, low-power awareness of which services are nearby, Wi-Fi Aware is the Wi-Fi Alliance’s other answer.