difference between getConnectionInfo() and getScanResults() to detect signal strength changes
Asked Answered
V

2

6

I'm trying to detect signal strength changes in a wifi connection. I'm confused of which method I should use in my BroadcastReceiver. What is the difference between using getConnectionInfo() and getScanResults() - from which then I can use relevant method to get the rssi value?

For example: if I use getConnectionInfo(), then later on I use getRssi(). Or I could use getScanResults() and the "level" property.

I display their values using Toast and it doesn't always show same values. When wifi conn is lost, the getConnectionInfo().getRssi() shows -200, while result.level still shows its previous value.

Any thoughts? Thanks!

String netSSID = wifi.wifiMgr.getConnectionInfo().getSSID();
int netRSSI = wifi.wifiMgr.getConnectionInfo().getRssi();

List<ScanResult> results = wifi.wifiMgr.getScanResults();
for (ScanResult result : results) {
    if (result.SSID.equalsIgnoreCase(netSSID)) {
        anothernetRSSI = result.level;
    }
}
Vinculum answered 7/12, 2010 at 15:22 Comment(0)
T
2

In One word, RSSI is available only between your device and access point that you are connected to it. (RSSi is the level of signal of an access point that you are connected to it)

but when you want to get the level of all in range wifi access points you should use startScan and get scanResult and get level property for each in range wifi access point.

is this useful?

Tannic answered 2/6, 2012 at 5:39 Comment(0)
C
1

You use getScanResults() only if you use startScan(). A scan is asynchronous, sending a SCAN_RESULTS_AVAILABLE_ACTION broadcast when it is completed. And, the scan results will be for whatever access points the scan finds, which may include access points other than the one you are connected to, if you are connected to anything.

Cucullate answered 7/12, 2010 at 16:25 Comment(2)
Please see the code snippet There I use those two methods to detect rssi value from current connection. And yes, I use startScan(). Ok, so in this case it's just not right to use getConnectionInfo().getRssi() ? What about sending RSSI_CHANGED_ACTION broadcast and then use intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, 0) to get the new rssi value? Is this also the same case as SCAN_RESULTS_AVAILABLE_ACTION, which retrieve any access points? So it might give back rssi value of another AP as long as the value is different from the previous one?Vinculum
According a book I just read, RSSI_CHANGED_ACTION gives current rssi of connected wifi network. So now in my understanding, we can use one of the three methods to display rssi changes. But there is specific condition for each: 1. If you broadcast SCAN_RESULTS_AVAILABLE_ACTION (and thus, use startScan()), use getScanResults() and retrieve the "level" property for the network you're currently connected to. 2. Use getConnectionInfo().getRssi() updated every x seconds. 3. Or if you broadcast RSSI_CHANGED_ACTION, use the EXTRA_NEW_RSSI - which in my case, should serve better to detect rssi changes.Vinculum

© 2022 - 2024 — McMap. All rights reserved.