我正在使用android wifi应用程序。我从wifiManager.getScanResults()
创建了wifi列表。现在我有两个相同SSID
的问题。我希望基于最强的信号强度将两个相同的SSID
缩短为一个。请帮我解决这个问题。
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));
}
答案 0 :(得分:1)
wifiSRList已排序,因此请尝试检查wifiListString是否包含您的ssid并忽略重复项。
String ssid="";
for (int i = 0; i < wifiSRList.size(); i++) {
ssid=wifiSRList.get(i).SSID;
if(!wifiListString.contains(ssid)){
wifiListString.add(ssid);
}
}
但首先需要将数组wifiListString解析为List。例如:
Arrays.asList(wifiListString ).contains(ssid)