Wi-Fi Direct plugin
Some devices running Android 4.0 and later support Wi-Fi Direct, which has a legacy mode that allows older devices to connect to WFD devices. The legacy mode creates an access point on the WFD device, with a random SSID and password that must be communicated to the other device out of band. The other device connects as a client in the usual way. The access point doesn't share the WFD device's internet connection, if any.
This could be useful when devices are in wifi range of each other but there's no wifi network; the SSID and password will have to be synced across some other transport (e.g. Bluetooth). When adding contacts via QR codes, the SSID and password can be included in the QR code.
Get the WifiP2pManager
system service, call initialize()
, then call createGroup()
to create an access point. Call requestGroupInfo()
to get a WifiP2pGroup
, then call getNetworkName()
and getPassphrase()
and to get the transport properties.
After connecting to the access point, how does the client know the access point's IP address? WifiP2pGroup.getOwner()
returns a WifiP2pDevice
, which contains a MAC address but not an IP address.
It seems from this example code that WifiP2pInfo.groupOwnerAddress.toString()
can be passed as the hostname to Socket.connect()
:
http://www.cse.unsw.edu.au/~ezarepour/COMP9336/WiFiDirectActivity.java
Presumably we can put that string in the transport properties with the SSID and password.
We may be able to advertise the access point's current SSID and password (in encrypted and obfuscated form) via WFD service discovery:
- Alice creates a legacy mode AP via
WifiP2pManager.createGroup()
- The AP has a random SSID and password, which Bob doesn't know
- Alice packs the SSID and password into a
WifiP2pServiceInfo
- Alice advertises the service via
WifiP2pManager.addLocalService()
- Bob discovers the service via
WifiP2pManager.addServiceRequest()
- Bob unpacks the SSID and password and connects to the AP as a legacy client
However, the Thali developers have run into performance and stability problems with WFD service discovery, so this may not be a viable approach.