我正在尝试通过我的 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。
任何人都可以帮助我吗?