duplicate SSID in scanning wifi result

十年热恋 提交于 2019-12-04 15:00:38

Are you having several router modems for the same network? For example: A company has a big wireless network with multiple router modems installed in several places so every room has Wifi. If you do that scan you will get a lot of results with the same SSIDs but with different acces points, and thus different signal level.

EDIT: According to Walt's comment you can also have multiple results despite having only one access point if your modem is dual-band.

vikoo

use below code to to remove duplicate ssids with highest signal strength

public void onReceive(Context c, Intent intent) {
    ArrayList<ScanResult> mItems = new ArrayList<>();
    List<ScanResult> results = wifiManager.getScanResults();
    wifiListAdapter = new WifiListAdapter(ConnectToInternetActivity.this, mItems);
    lv.setAdapter(wifiListAdapter);
    int size = results.size();
    HashMap<String, Integer> signalStrength = new HashMap<String, Integer>();
    try {
        for (int i = 0; i < size; i++) {
            ScanResult result = results.get(i);
            if (!result.SSID.isEmpty()) {
                String key = result.SSID + " "
                        + result.capabilities;
                if (!signalStrength.containsKey(key)) {
                    signalStrength.put(key, i);
                    mItems.add(result);
                    wifiListAdapter.notifyDataSetChanged();
                } else {
                    int position = signalStrength.get(key);
                    ScanResult updateItem = mItems.get(position);
                    if (calculateSignalStength(wifiManager, updateItem.level) >
                            calculateSignalStength(wifiManager, result.level)) {
                        mItems.set(position, updateItem);
                        wifiListAdapter.notifyDataSetChanged();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!