getConnectionInfo() 和 getScanResults() 检测信号强度变化的区别
我正在尝试检测 wifi 连接中的信号强度变化。我很困惑应该在 BroadcastReceiver 中使用哪种方法。使用 getConnectionInfo() 和 getScanResults() 有什么区别 - 然后我可以使用相关方法来获取 rssi 值?
例如:如果我使用 getConnectionInfo(),那么稍后我会使用 getRssi()。或者我可以使用 getScanResults() 和“level”属性。
我使用 Toast 显示它们的值,但它并不总是显示相同的值。当 wifi conn 丢失时, getConnectionInfo().getRssi() 显示 -200,而 result.level 仍显示其先前的值。
有什么想法吗?谢谢!
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;
}
}
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,RSSI 仅在您的设备和您所连接的接入点之间可用。 (RSSi 是您所连接的接入点的信号电平)
但是当您想要获取范围内所有 wifi 接入点的电平时,您应该使用 startScan 并获取 scanResult 并获取每个范围内 wifi 接入的 level 属性观点。
这有用吗?
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?
仅当使用
startScan()
时才使用getScanResults()
。扫描是异步的,完成时发送SCAN_RESULTS_AVAILABLE_ACTION
广播。而且,扫描结果将针对扫描找到的任何接入点,其中可能包括除您所连接的接入点之外的接入点(如果您连接到任何设备)。You use
getScanResults()
only if you usestartScan()
. A scan is asynchronous, sending aSCAN_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.