13

I'm trying to make a multiplayer game for Android via WiFi direct. I followed the instructions on http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html in order to connect to devices.

The ActionListener i use with discoverPeers() returns successfully, but then i never receive the WIFI_P2P_PEERS_CHANGED_ACTION intent upon which i would call requestPeers(). Strangely when i go into WiFi direct system settings on one device, the other is able to successfully detect it through my app. Do i need to make my device discoverable in my app or something? I haven't found anything to indicate that in the Android developer resources regarding WiFi P2P. There is WiFi direct for service discovery, but that's something else entirely, isn't it?

cargath
  • 832
  • 8
  • 18
  • 1
    Same problem here. Ever track down what the issue was? – lostintranslation Jun 17 '15 at 14:00
  • Answer here is a bit dated, but may show you where to look: [How to be notified when a peer is no longer available in the Wi-Fi Direct range?](http://stackoverflow.com/questions/21072081/how-to-be-notified-when-a-peer-is-no-longer-available-in-the-wi-fi-direct-range). – Vikram Dec 05 '15 at 07:46
  • did you find a solution ?? – Santanu Sur Jun 09 '18 at 13:13

4 Answers4

3

You need to run discoverPeers() on other devices as well.
Now you will receive the WIFI_P2P_PEERS_CHANGED_ACTION intent

Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
Gaurav Gupta
  • 1,929
  • 4
  • 21
  • 40
0

Add WIFI_P2P_PEERS_CANGED_ACTION into your broadcast receiver intent-filter.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
László Magyar
  • 355
  • 1
  • 16
  • 1
    Well, yes. As i said, i followed the instructions on http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html. I'm not sure what other information to provide. I could post code, but it looks like the one in the official example, so that wouldn't be very interesting either. – cargath Nov 24 '14 at 22:36
0

You have to find devices under Settings/Wifi/Direct Wifi/Available devices

Samuel Kogan
  • 121
  • 1
  • 3
0

There are two factors contributing to the problem:

  1. The event never occurred and not broadcast to others.
  2. Although the event occurred, the intent filter does not catch it.

In my case, I found that the receiver does not get the event properly. the reason was because I didn't registerReceiver to the intent filter properly.

after I do

intentFilter.addAction(WifiP2PManager.WIFI_P2P_PEERS_CHANGED_ACTION), 

I didn't do

ct.registerReceiver(bReceiver, intentFilter).

ct is activity or context, and bReceiver is WifiDirectBroadcastReceiver. I firstly wrote

ct.registerReceiver(bReceiver, intentFilter),

but, it was not executed properly.

Nimantha
  • 6,405
  • 6
  • 28
  • 69