1

使用本教程: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 活动本身中?在哪里?

4

1 回答 1

2

如果继续该示例,您可以看到在您发布的代码中创建的对象 ( peerListListener) 已在onReceive()方法中使用。似乎他们搞砸了并将其重命名为peerListener那里。

于 2012-12-24T16:50:20.400 回答