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?
Wi-Fi Direct (also known as peer-to-peer or P2P) allows your application to quickly find and interact with nearby devices, at a range beyond the capabilities of Bluetooth. The Wi-Fi Direct (P2P) APIs allow applications to connect to nearby devices without needing to connect to a network or hotspot.
However, using Wi-Fi Direct (P2P) Service Discovery allows you to discover the services of nearby devices directly, without being connected to a network. You can also advertise the services running on your device. These capabilities help you communicate between apps, even when no local network or hotspot is available.
Wi-Fi Peer-to-Peer (P2P) allows Android 4.0 or later devices with the appropriate hardware to connect to each other via Wi-Fi without an access point. Android Wi-Fi P2P framework complies with the Wi-Fi Direct standard.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With