0
我正在實施一個應用程序,我必須使用WiFi p2p發現設備並記錄有關每個檢測到的設備的一些數據。我遇到的問題是,當設備從在線到離線時,WifiP2pDeviceList
未更新,因此它將刪除此設備。但是,當檢測到新設備時,它通常會添加到列表中。那麼我的代碼有什麼問題?Android:Wifi P2P列表沒有正確更新
我已經看到這篇文章(WIFI P2P discovery list is not getting refreshed?),它與我有什麼不同。
/**
* A Table of devices that displays all peers and shows the corresponding
* info about them.
*/
public class DevicesTable extends Fragment implements PeerListListener {
protected static List<WifiP2pDevice> peers = new ArrayList<WifiP2pDevice>();
View mContentView = null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mContentView = inflater.inflate(R.layout.table, null);
return mContentView;
}
/**
* @return this device
*/
public WifiP2pDevice getDevice() {
return device;
}
@Override
public void onPeersAvailable(WifiP2pDeviceList newPeers) {
ClientActivity x = (ClientActivity) ClientActivity.context;
if (!x.wifiP2pScanThread.isScanning()) {
return;
}
peers.clear();
peers.addAll(newPeers.getDeviceList());
ArrayList<String> onlinemacs = new ArrayList<>();
if (peers.size() == 0) {
Log.d(ClientActivity.TAG, "No devices found");
} else {
for (WifiP2pDevice dev : peers) {
//do something
}
}
}
}