使用本教程:http: //developer.android.com/training/connect-devices-wireless/wifi-direct.html#fetch
我已经成功地获得了教程中的这部分代码:
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;
}
}
}
我现在不确定将获取对等列表的代码放在哪里。它是在我的广播接收器中,还是在 wifi 活动本身中?在哪里?