android中 获取WiFi信息并计算wifi的信号强度
一、首先获得WifiManager
WifiManager wifiManager=(WifiManager) getSystemService(WIFI_SERVICE);
添加权限:
二、 WifiInfo wifiInfo=wifiManager.getConnectionInfo();//当前wifi连接信息
List scanResults=wifiManager.getScanResults();//搜索到的设备列表
for (ScanResult scanResult : scanResults) {
tv.append(“\n设备名:”+scanResult.SSID
+” 信号强度:”+scanResult.level+”/n :”+wifiManager.calculateSignalLevel(scanResult.level,4));
}
附WifiManager中计算级别的代码:
public static int calculateSignalLevel(int rssi, int numLevels) {
if (rssi <= MIN_RSSI) {
return 0;
} else if (rssi >= MAX_RSSI) {
return numLevels – 1;
} else {
int partitionSize = (MAX_RSSI – MIN_RSSI) / (numLevels – 1);
return (rssi – MIN_RSSI) / partitionSize;
}
}
http://blog.csdn.net/wang1588143/article/details/6653475