Reputation: 930
I'm working in the android wifi Application. I created the wifi list from wifiManager.getScanResults()
. Now I have problem with two same SSID
. I want short the two same SSID
in to one based on strongest signal strength. Please help me to solve this problem.
WifiReceiver.java(extends BroadcastReceiver)
:
@Override
public void onReceive(final Context context, Intent intent) {
wifiSRList = wifiManager.getScanResults();
Collections.sort(wifiSRList, new Comparator<ScanResult>() {
@Override
public int compare(ScanResult lhs, ScanResult rhs) {
return (lhs.level > rhs.level ? -1 : (lhs.level == rhs.level ? 0 : 1));
}
});
for (int i = 0; i < wifiSRList.size(); i++) {
wifiListString[i] = (wifiSRList.get(i).SSID);
}
wifiListView.setAdapter(new ArrayAdapter<>(context, R.layout.custom_wifi_list, wifiListString));
}
Upvotes: 0
Views: 416
Reputation: 37
wifiSRList is sorted so try to check if wifiListString contains your ssid and ignore duplicates.
String ssid="";
for (int i = 0; i < wifiSRList.size(); i++) {
ssid=wifiSRList.get(i).SSID;
if(!wifiListString.contains(ssid)){
wifiListString.add(ssid);
}
}
but first you need to parse your array wifiListString to List. Example:
Arrays.asList(wifiListString ).contains(ssid)
Upvotes: 1