Android中每秒每秒进行WiFi网络扫描的问题

| 我正在尝试通过我的Android设备扫描可用的wifi网络。这是代码段-
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);

                registerReceiver(new BroadcastReceiver() {
                    @Override 
                    public void onReceive(Context context, Intent intent) {
                        WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
                        List<ScanResult> results = wifiManager.getScanResults(); 

                        //int newRSSI= intent.getIntExtra(wifiManager.EXTRA_NEW_RSSI, 0);
                        //WifiDistance wifi_dis = new WifiDistance();

                        for (ScanResult result : results) {

                            textView.append(\"\\nSSID=\"+result.SSID + \", \" + \"Strength(dBm)=\" + result.level + \", AP: \"+ result.BSSID);
                            wifi+=\"\\n\"+result.SSID + \", \" + result.level + \", \"+ result.BSSID;


                            //WifiDistance.getWifiDistance().distanceCalc(result.BSSID, result.level);
                    }, 
                    new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

                    // Initiate a scan.
                wifiManager.startScan();

                }
我将其置于动作处理程序下,例如,如果按下按钮,它将开始扫描。现在我的问题是,当我的手机连接到特定网络时,它不会自动更新wifi扫描结果。它只是保留了较旧的数据。我想按此按钮开始扫描,并每秒更新一次扫描结果。 我正在HTC Magic中使用OS 2.1。 谁能帮我吗?     
已邀请:
        究竟您如何尝试每秒更新一次扫描结果? 在我看来,因为您仅在接收到广播时才更新列表,并且startscan代码出现在列表填充之后。 相反,您可以使用计时器任务来更新运行单独的方法,该方法每秒更新一次Scanresult列表,然后再次运行循环。 就像是:
Public void RunEverySecond(){
List<ScanResult> results = wifiManager.getScanResults();

for (ScanResult result : results) {

                        textView.append(\"\\nSSID=\"+result.SSID + \", \" + \"Strength(dBm)=\" + result.level + \", AP: \"+ result.BSSID);
                        wifi+=\"\\n\"+result.SSID + \", \" + result.level + \", \"+ result.BSSID;

                }
}
也许?     

要回复问题请先登录注册