Android WiFi Direct Example
Android WiFi Direct Example
Deprecated now. This blog is old now. Also blog is intend to cover only basics of wifi direct technology.
Wi-Fi Direct allows Android 4.0 (API level 14) or later devices with the right hardware to connect directly to each other via Wi-Fi without an intermediate access point. Using these APIs, you can discover and connect to other devices when each device supports Wi-Fi Direct, then communicate over a speedy connection across distances much longer than a Bluetooth connection. This is useful for applications that share data among users, such as a multiplayer game or a photo sharing application.
The WifiP2pManager class provides methods to allow you to interact with the Wi-Fi hardware on your device to do things like discover and connect to peers. The following actions are available:
You can find all set up details http://developer.android.com/guide/topics/connectivity/wifip2p.html
I will try to explain few more things about wi-fi direct.
- For peer-to-peer data transmission it does not use any kind of traditional home, office or hotspot network.
- For Security purpose it uses WPA2 encryption protection.
- It can transfer data at the speed of 2.5 to 3.0 Mbps. (Tested on Galaxy Tab-2 and Nexus 7 Tab)
- Wi-Fi Direct can operate at up to 100m. Some reference site says 656 feet too.
- We can also set up group between devices for which hardware support is offered for wifi direct.
Below is the process explained to perform this feature.
- Check whether wifi direct is available or not using WifiP2pManager.WIFI_P2P_STATE_ENABLED.
- To discover peers that are available to connect to, call discoverPeers() to detect available peers that are in range.
- If the discovery process succeeds and detects peers, the system broadcasts the WIFI_P2P_PEERS_CHANGED_ACTION intent, which you can listen for in a broadcast receiver to obtain a list of peers.
- When you have figured out the device that you want to connect to after obtaining a list of possible peers, call the connect() method to connect to the device.
- To transfer the data it uses Sockets. So combination of ServerSocket and Socket class from network package performs actual sending and receiving of the file.
Find a simple example : WifiDemo.zip
comments powered by Disqus