Class WiFiDirect
java.lang.Object
com.codename1.io.wifi.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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidconnect(WiFiDirectPeer peer, WiFiConnectCallback callback) Forms a P2P group withpeer.static voidDrops the current group, if any.static booleantrueif the current platform implements WiFi Direct.static voidstartDiscovery(WiFiDirectListener listener) Starts peer discovery.static voidStops peer discovery and detaches all listeners.
-
Method Details
-
isSupported
public static boolean isSupported()trueif the current platform implements WiFi Direct. -
startDiscovery
Starts peer discovery.listeneris invoked on the EDT for every peer list change. CallstopDiscovery()to release radio resources when you're done. -
stopDiscovery
public static void stopDiscovery()Stops peer discovery and detaches all listeners. -
connect
Forms a P2P group withpeer. 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.
-