If you continue with the example, you can see that the object created in the code you posted (peerListListener
) is used in the onReceive()
method. Seems like they screwed up and renamed it to peerListener
there though.
Wi-FI Direct tutorial - Where does the PeerListListener go? [closed]
-
12-12-2021 - |
Question
Using this tutorial: http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html#fetch
I have gotten to this section of code in the tutorial successfully:
private List peers = new ArrayList();
...
private PeerListListener peerListListener = new PeerListListener() {
@Override
public void onPeersAvailable(WifiP2pDeviceList peerList) {
// Out with the old, in with the new.
peers.clear();
peers.addAll(peerList.getDeviceList());
// If an AdapterView is backed by this data, notify it
// of the change. For instance, if you have a ListView of available
// peers, trigger an update.
((WiFiPeerListAdapter) getListAdapter()).notifyDataSetChanged();
if (peers.size() == 0) {
Log.d(WiFiDirectActivity.TAG, "No devices found");
return;
}
}
}
I am now unsure of where to put this code that obtains a peer list. Does it go in my broadcast receiver, or the wifi activity itself? And where?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow