Android WifiP2p - Get notified when a discovered d

2019-04-08 17:06发布

问题:

I'm developing a Wifi-direct app in which i'm listing the devices that are available and when the device goes to "unavailble" status i have to remove it from the list.

I tried with the WifiDirectDemo sample, it successfully adds discovered devices in the list but when the device goes unavailable it is not getting notified. "WIFI_P2P_PEERS_CHANGED_ACTION" intent is not fired when device goes unavailable.

When i try "discoverPeers" again, "onPeersAvailable" method gets the device list that are already discovered. It is not removing the unavailble devices.

Is there any way to get notified when the device goes unavailable?

回答1:

Have a look at this post

in sum: peers who go out of the range will be automatically delete in the peers list after some time - this could belong until 1 minute. I test it with an s4 and s5 mini device. s5 mini discovered the s4 device - when i turned off wifi on the s4 device it took about 20 seconds, then the s5 mini device broadcastes a PEERS_CHANGED Action an the s4 didn't appera any longer in the devicelist...