How to synchronize WifiManager.startscan() and WifiManager.getScanResults?

丶灬走出姿态 提交于 2019-12-23 04:38:33

问题


I am trying to scan for access points every second. Here's what I am doing.

      if (isScanning()) {               
            new Timer().schedule(new TimerTask() {
                @Override
                public void run()
                {   
                    results = manager.getScanResults();
                    manager.startScan();                                            
                }                   
            }, 0,1000); 
            adapter.notifyDataSetChanged();

I am displaying the results using a BaseAdapter.

public View getView(int position, View convertView, ViewGroup parent) {

    ScanResult result = results.get(position);

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.network_list_row, null);

    }
    // Get textview fields
    TextView txtSSID = (TextView) convertView.findViewById(R.id.txtSSID);
    TextView txtBSSID = (TextView) convertView.findViewById(R.id.txtBSSID);
    TextView txtCapabilities = (TextView) convertView
            .findViewById(R.id.txtCapabilities);
    TextView txtFrecuency = (TextView) convertView
            .findViewById(R.id.txtFrecuency);
    TextView txtLevel = (TextView) convertView.findViewById(R.id.txtLevel);

if (result.SSID.equalsIgnoreCase(ScanNetworks.manager
                .getConnectionInfo().getSSID()))
                {
            txtSSID.setText(convertView.getContext().getString(
                    R.string.ssid_msg, result.SSID));
            txtBSSID.setText(convertView.getContext().getString(
                    R.string.bssid_msg, result.BSSID));
            txtCapabilities.setText(convertView.getContext().getString(
                    R.string.capabilities_msg, result.capabilities));
            txtFrecuency.setText(convertView.getContext().getString(
                    R.string.frecuency_msg,
                    Integer.toString(result.frequency)));
            txtLevel.setText(convertView.getContext().getString(
                    R.string.signal_level_msg,
                    Integer.toString(result.level)));
            ;

I see a lot of duplicates when I display the results of the scan. I know there is an overlap between every second the startScan() is called. Is there a way I can eliminate the duplicates in the display? Also, how do I synchronize the startScan() and getScanresults() call? Please advice. Thanks

来源:https://stackoverflow.com/questions/8763397/how-to-synchronize-wifimanager-startscan-and-wifimanager-getscanresults

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!