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

左心房为你撑大大i 提交于 2019-12-21 01:12:24

问题


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;
    }
}

回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/4378280/difference-between-getconnectioninfo-and-getscanresults-to-detect-signal-str

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