Android/java Wifi Direct Peer List
Solution 1:
I can see you did an initial discovery when constructing you WiFiDirectBroadcastReceiver
and then in your Activity.onResume() you first construct WiFiDirectBroadcastReceiver and then registerReceiver().
@OverridepublicvoidonResume() {
super.onResume();
_broadcastReceiver = newWiFiDirectBroadcastReceiver(_manager, _channel, this, _peerListListener);
registerReceiver(_broadcastReceiver, _intentFilter);
}
The problem that you do not see the response come back is probably because of the sequence.Try move discoverPeers() to Activity.onResume() should solve the problem.
Solution 2:
You're missing a call to DiscoverPeers:
To start searching for nearby devices with Wi-Fi Direct, call discoverPeers().
The specific app logic for when you want that initial discovery to happen will determine where in your code that happens. In the API samples for SDK 17, this happens when an option item is clicked from the menu. This could easily be moved to the onResume method (this will be initiated every time the activity is resumed, or in the click listener for a button on the screen.
For future troubleshooting, I would recommend keeping the WiFiDirectBroadcastReceiver class inside the Activity's class (unless you need to reuse the code) for ease of use with callbacks -- you can access the outer class's methods directly from the inner class and make this a bit easier to troubleshoot.
Solution 3:
Try changing this:
_manager.requestPeers(_channel, _peerListListener);
to this:
_manager.requestPeers(_channel, _activityRef._peerListListener);
Solution 4:
Google is providing a Wifi Direct example since Oct 2011: https://android.googlesource.com/platform/development/+/master/samples/WiFiDirectDemo
I added this link because it took me a while to find it (original link is reffering to Wifi P2P Demo, not WiFiDirectDemo).
Post a Comment for "Android/java Wifi Direct Peer List"