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
I want to build Wi-FI based messenger could you help me out with it. Wi-Fi P2P api could help to build it ?
Yes, you can definitely build such things, you can follow this demo https://github.com/life0fun/wifi-direct-chat
I want build file sharing application using hotspot could you help to build it?
Yes, you can definitely build such things, you can follow this demo https://github.com/life0fun/wifi-direct-chat
Hi i want to build an android application that can be use to chat through wifi from android sdk …can you help me?
Hi Akhazhu please read previous comments I already suggested some demo app to other visitors.
i tried your code but its transferring files from client to server. This is unidirectional transfer. i want to achieve Bi Directional transfer of data. Tell me how can i achieve that.
Please read previous comments I already suggested some demo app to other visitors.
Can we achieve wifi printing with this demo.if no how can we achieve.?
These two will help you with wifi-printing
http://www.brother.com/product/dev/mobile/android/
https://developers.google.com/cloud-print/?hl=en
great tutorial,
can you give example oh android app that uses wifi to send digital values like 1’s and 0’s to be received by a router and directly give the info to ARDUINO for comparison.. its like a switch.. i am working on our thesis about home automation… hoping for positive feedback 🙂
I don’t have that much customized example. But you can surely send 0 and 1 as bit using this example. Needs lot of modification though.
hello I want to detect the device’s mac address if there wifi is on not the hotspot and list of such type of devices should be shown in my mobile so what should i do..
Hi Lalit,
MAC address of your wifi and wifi-direct can be different . Be careful about that.
GET WIFI MAC ADDRESS
WifiManager wifiMan = (WifiManager) this
.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
MAC_ADDRESS = wifiInf.getMacAddress();
GET WIFI-DIRECT MAC ADDRESS
WifiP2pDevice device = (WifiP2pDevice) intent
.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
String myMac = device.deviceAddress;
i want to scan the list of devices and get their mac address
whose wifi is on not hotspot in my mobile is it possible and how….
Hello sir I have solved this problem thank you for reply now I want to know is it possible to read the content from kismon in kismet os with raspberry pi device and using comfortable programming language insert that data in database…
How can i show my data transfer speed when mobile data is enabled ,and also this could change dynamically sec-sec?
Its pure calculation. You need to observe your bytes and calculates the transmit speed.
can i make a voice call using wifi direct?
Do not have much idea, but you can look for SIP and check the feasibility integrating it with Wifi P2P
Sir, I want to discuss deeply about an idea of an app to be made on wifi-direct, and i think and hope that you can help me with it. It would be very nice if you could reach me through Email ASAP.
I want create multi hop connections between devices using wifi direct, Device A wants to reach C but is not in range, so another device B which is both in range of A and C will take the message from A and pass it to C.
Really need help sir.
Thanks
i want to send all types of files using wifi direct . . i use the wifi direct demo source code but i am being able to send only images. . how would i modify it so that i would be able to send all types of files and the receiver be able to receive it.
hello how can i sent picture to multi devices using wifi direct can you help me?
Hi Hardik!
We are working on developing an app where we need to send push notification to another app through wifi. Is it possible with this?
Would Appreciate a detailed guidance as I am new Android Development.
Thanks in Advance
Satish Sawra
Hi Sir,
We are also working on developing an app where we need to send push notification to another app through wifi. Is it possible with this?
Please give a detailed guidance as I am new Android Development.
Thanks in Advance
Hemant Khatri
Please refer this https://github.com/life0fun/wifi-direct-chat. See how they have implemented chat . You can mimic similar thing to achieve your requirement.
hi sir , i want to transfer data using wifi in android studio.
can we make more than two phones to talk simultaneously over wifi direct?
Hello sir,
I am currently working on an app to make use of wifi-direct for communication with multiple devices. Is it possible to use wifi-direct to form an ad-hoc network?
I create chat application in andriod for clg project .pls help to create the app
I installed this demo app on two mobile phones and no matter from which device i make the connect request…ONE OF THE DEVICE ALWAYS ACTS AS A SERVER AND THE OTHER AS CLIENT….how do i make a client to my device? please help!
Can you please upload the zip-file some where else? My chrome tells me that its harmful.
hello sir…
Sir i want to develope a app that detects wifi direct clients and it needs to save the clients name in sql lite and need to restrict some clients, is it possible …
if any code samples are already there please send the link…
thanx in advance..
Hi Hardik,
I was curious to know if sharing to mutiple devices is possible using WifiP2pManager, just like how Xender does it. Can you share something if you have or know of?
hey hardik how your demo app works ? can u please tell me?
Install app in two devices and run them. Connect two devices and follow the steps.
Hi,
Good tutorial. I want to know if its possible that we can connect Android device with PC through wifi direct having our custom app on both android and PC to send signal from android to PC to start a task on PC.
I tried you app like below mentioned steps
i used 3 mobile for it
> created hotspot in mobile 1
> connect mobile 2 and 3 with mobile 1
> In mobile 2 i installed your app
> now searching peer from mobile 2, but nothing was came
all mobile have jelly bean
I installed your app in one device and and that is connected to router
one more anderoid lolipop device connected to router
now i m searching peers from your app but no result spinner is running….. running….. and running….
can you please help me that i am going on correct way or not?
the tutorial is really good how can we transfer audio and video files using wifi direct
how can we send the name of file being transfered and keep the same name on the second phone alos
Can you show a sample on searching an android device using wifi ?
Is already part of example.
Hii,
i want to develop Group Chat Applicaton using wifi could u please help me to develop this…
I have already provided some links. Find in above chats
hi,
I am developing an application.in that I need to discover the devices connected on a device’s hotspot and I need to do a data transfer from all the connected clients to the owner.need your help on that bro
can we use wifi direct to gaming purpose is it possible because i developed one app for chatting and sharing file but i want add multiple player game in it is it possible dear hardik
Wifi Direct requires users to be in the same network. If you and user are not in same network, wifi direct will not work.
I like your app. I just want to know that is there any modification that will help me to send data to my PC.
Actually I developed a software in which the input came from an app. I’m using arduino and wifi module to connect the mobile through wifi it get connected but I can’t find a way to send data or input to the software. if you can help me it will be great for me.
hey Mr. Hardik, I am Keval Patel, I am doing my project on the wifi transfer of audio, video and image from android to PC. I am stucked into the backend coding, so can u send me the link for the code of similar app for refrence so that I can get out of this.
Hey Mr. Hardik , I am Keval Patel. I am working on the project that sends image, audio and video from android device to PC via Wifi. But I am stucked in backend coding. So can u send me links of code for same for refrence so that I can get out of this.
I am not good enough on server side code.
Hi ,
I created an application for exchanging data using wifi direct. It created sockets in serverthread and client thread class to interchange data. Now , the problem which i am getting is the connection is very unrealible. It takes a hell lot of time to discover peers or sometimes breaks the connection in between. Can you please tell how can i make this connection set up stable .
Thanks in advance
You yourself created sockets ?
Hi.
Is there any way to connect more than 1 device at a time using wifi direct?
Yes, the Wi-Fi Direct specifications explain it is possible to create a 1 to many connection. One of the devices will act as a group owner (think it as an access point). I have been able to create a Wi-Fi Direct network with 3 devices during some tests.
As all the devices have to be in the range of the group owner, you are sure that your message will arrive to the second client. 1st client -> group owner -> 2nd client
Please I want to know if the wifi p2p is just for two devices. can you connect to like 30 devices with wifi p2p. im walking on a project. please help. Thanks a lot for the great tutorial
Yes, the Wi-Fi Direct specifications explain it is possible to create a 1 to many connection. One of the devices will act as a group owner (think it as an access point). I have been able to create a Wi-Fi Direct network with 3 devices during some tests.
As all the devices have to be in the range of the group owner, you are sure that your message will arrive to the second client. 1st client -> group owner -> 2nd client
Thank you so much. I really appreciate
Nice tutorial sir
hello sir, i want to develop android app with multiple group connected.how can i achieved that and where can i get references?
Hi ,
The code is very good.Can u plz tell how to take real-time camera pictures with the use of wifi-direct.
sir
i want to make an app for, remote of a toy car. can you help please.
i want to send four characters to my toy car F,R,L,R
hi,
How to make app to app audio call in android?
online and offline group create and video streaming and audio streaming both in online and offline with group member using wifi
help me about this
rajaakukad4@gmail.com
Hello Hardik
Nice job you are doing…
i am Harsh…working as you but in electronics….
i am beginner in android because i from electronics field. well i need to create two android app. 1st one work as server(wifi hot spot) and continuously receive data over wifi port 80 (http) and second one work as client which sends specified string on some button press over wifi. can you help me to do this task??
Hello man!
Nice tutorial, I’d like to know if it’s possible simulating the connection between the Android Studio emulator and a real device, and if it is, how could I do that?
Thanks in advance.
hi
i want writ this cod with AndroidStudio can you help me?
Hey i would like to get totla transmitted and recived data using mobile tethering. Can you please, Suggest me how can i do this.
Below is my requirement like-
Name of App Wifibud How it works: User #1 has extra cellular data to sell using tethering. User #2 Needs more data. User#1 starts Wifibud app in a cafe. User #2 Gets “Wireless Networks Available” notification. He clicks the Wifibud network named “Wifibud”. Then gets a splashpage that provides user with 4 options. Buy 50mb . buy 150 mb . buy 500mg. buy 1gb.. User #2 Chooses one and gets charged using app store.(in store purchases).
Hi Sir,
Actually, instead of wifi p2p I want to use wifi and hotspot to send data b/w two android devices. I hv already done connecting two device in a same N/W using wifi nd hotspot. Can you tell me how to send data b/w them further.
Hello;
i’m very beginner in Android , so please be patient , how can i open your demo file in Android studio !! I try to :
Open project from Studio then i click on your demo folder in my desktop then the project opened but without Green Run command, so how can i run it?
thanks
Hi,
My requirement is to connect two devices via Wifi-direct in the background to send a certain data. I have explained the flow below.
1.In background Device A tries to connect to Device B via Wifi-Direct/WifiP2P this should happen Without User;s interference in the foreground.
2. Then in background certain text data should be sent to other device. This also should happen inthe background.
So my question is :- Is it possible to estabnlish the P2P connection the background without users interference.
I really need some help on how to connect two devices to each other and control the other devices setting like increasing the light intensity of the other device. Please help!!!
Do we need any more configuration to make to do peer to peer wifi file sharing between PC and Android?
I mean any software installation,..wifi configuration.etc…?
Thanks
i want to make WIFI-DIRECT audio calling apps in android ……can you help me..please
Hi Bro….I am planning to implement Buzzer type of functionality for my Quiz App. Some Thing like this :
http://ibuzzedfirst.com/
After Searching on the same I came to know That It is Possible By Using WifiP2P Connection between devices.
Can U please guide me on the same…Thanks Bro.
Sir how do you send other files instead of just images?
hello sir.
i want to make a quiz app for my minor project.In that app i want to connect other devices through hotspot.one device host the quiz and that quiz must be display same on all devices connected to that hotsopt.And result of that qiuz also display on all the connected device.
plz sir tell me hoe can i resolve this problem.
Yes wifi p2p is the answer. Check recent demos on android developer portal.
do you know how to get client IP address,
the API seemly provide owner info
Great Tutorial! thx a lot
Great ,Thank You
Hi i need to Wi-Fi Peer to Peer can do multiple device connection.
Hi i need wifip2p to connect two devices to play a game
can you help???
Dear Sir,
I used your Wifi printout App giving error
failed to connect to /192.168.118.1 (port 8988) after 9000ms: isConnected failed: ECONNREFUSED (Connection refused)
so please provide me solution an soon ass possible
Dear Sir,
I used your Wifi printout App giving error
failed to connect to /192.168.118.1 (port 8988) after 5000ms: isConnected failed: ECONNREFUSED (Connection refused)
so please provide me solution as soon as possible