Reputation: 1367
I'm trying to scan available wifi network through my Android device. Here's the chunk of code -
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();
}
I have put this under a action handler such as if a button is pressed it starts scanning. Now my problem is, when my phone is connected to a specific network it does not update the wifi scanning result automatically. It just stays with the older data. I want to press the button to start scanning and update the scan result every second.
I'm using OS 2.1 in HTC Magic.
Can anyone help me please?
Upvotes: 2
Views: 2546
Reputation: 1841
Exactly how do you attempt to update the scan results every second?
it looks to me as you only update the list whenever a broadcast is received, and the startscan code appears after the List population.
Instead you could could use a timer task to update run a seperate method which updates the Scanresult list every second, and run the For-Loop again.
something like:
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;
}
}
maybe?
Upvotes: 2