# Class WiFiDirect

java.lang.Object
com.codename1.io.wifi.WiFiDirect

public final class WiFiDirect extends java.lang.Object

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 injects `CHANGE_WIFI_STATE`, `ACCESS_WIFI_STATE`, `ACCESS_NETWORK_STATE`, `ACCESS_FINE_LOCATION` (API 26+) and `NEARBY_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 `connect` reports failure.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `connect(WiFiDirectPeer peer, WiFiConnectCallback callback)`
  Forms a P2P group with `peer`.
  `static void`
  `disconnect()`
  Drops the current group, if any.
  `static boolean`
  `isSupported()`
  `true` if the current platform implements WiFi Direct.
  `static void`
  `startDiscovery(WiFiDirectListener listener)`
  Starts peer discovery.
  `static void`
  `stopDiscovery()`
  Stops peer discovery and detaches all listeners.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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.