public final class WiFiDirect
- Object
- WiFiDirect
WiFi Direct (Wi-Fi P2P) discovery and grouping.
WiFi Direct lets two devices form a peer-to-peer link without going through an access point. Use it for ad-hoc file transfer, multi-player games on a local network, or any other scenario where a router is unavailable.
Platform support
- Android: full support via
android.net.wifi.p2p.WifiP2pManager. The build pipeline injectsCHANGE_WIFI_STATE,ACCESS_WIFI_STATE,ACCESS_NETWORK_STATE,ACCESS_FINE_LOCATION(API 26+) andNEARBY_WIFI_DEVICES(API 33+) when this class is referenced. - iOS: not supported. iOS uses MultipeerConnectivity for similar scenarios; that API is intentionally out of scope here.
- Simulator: stubbed. Discovery returns no peers and
connectreports failure.
Methods
public static boolean isSupported() | true if the current platform implements WiFi Direct. |
public static void startDiscovery(WiFiDirectListener listener) | Starts peer discovery. |
public static void stopDiscovery() | Stops peer discovery and detaches all listeners. |
public static void connect(WiFiDirectPeer peer, WiFiConnectCallback callback) | Forms a P2P group with peer. |
public static void disconnect() | Drops the current group, if any. |
Inherited methods
Method details
isSupported
public static boolean isSupported()true if the current platform implements WiFi Direct.startDiscovery
public static void startDiscovery(WiFiDirectListener listener)Starts peer discovery.
listener is invoked on the EDT for every peer
list change. Call stopDiscovery() to release radio resources when
you’re done.stopDiscovery
public static void stopDiscovery()Stops peer discovery and detaches all listeners.
connect
public static void connect(WiFiDirectPeer peer, WiFiConnectCallback callback)Forms a P2P group with
peer. The user is shown a confirmation prompt
on both devices the first time they connect; subsequent connections
reuse the cached pairing where possible.disconnect
public static void disconnect()Drops the current group, if any.