I'm implementing an application where I have to discover devices using WiFi p2p and record some data about every detected device. The problem I'm having is that when a device goes from online to offline, the WifiP2pDeviceList
is not being updated so that it removes this device. But when a new device a detected it is added normally to the list. So what is the problem with my code?
I already saw this post ( WIFI P2P discovery list is not getting refreshed? ) and it is different from what I have.
/**
* 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
}
}
}
}