简体   繁体   中英

How to short list same SSID in Android Wifi?

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));

}

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM