I was looking on stackoverflow on how to sort a list based on signal strength (referred to as level
in the WifiManager library). I saw that you can use the function Collection.sort()
. However, I am confused where I put the fact that I want to sort the list via level
, where the highest number is at beginning and the lowest is at the bottom.
As you can see it returns a few things in each object: https://developer.android.com/reference/android/net/wifi/ScanResult.html I am not that advanced, but I know I can access the level by doing something like this
for (int i=0; i < scanList.size(); i++) {
System.out.println(scanList.get(i).level); // Prints the level for each access point
}
WifiManager myWifiManager;
myWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
myWifiManager.startScan();
List<ScanResult> scanList = myWifiManager.getScanResults();
Collections.sort(scanList);