WifiInfo中包含了当前连接中的相关信息。
getBSSID() 获取BSSID属性
getDetailedStateOf() 获取客户端的连通性
getHiddenSSID() 获取SSID 是否被隐藏
getIpAddress() 获取IP 地址
getLinkSpeed() 获取连接的速度
getMacAddress() 获取Mac 地址
getRssi() 获取802.11n 网络的信号
getSSID() 获取SSID
getSupplicanState() 获取具体客户端状态的信息
六、示例
====
1)获得WifiManager
WifiManager wifiManager=(WifiManager) getSystemService(WIFI_SERVICE);
2)获取Wifi信息
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中计算级别的代码:
/**
-
Calculates the level of the signal. This should be used any time a signal
-
is being shown.
-
@param rssi The power of the signal measured in RSSI.
-
@param numLevels The number of levels to consider in the calculated
-
level.
-
@return A level of the signal, given in the range of 0 to numLevels-1
-
(both inclusive).
*/
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;
}
}
3)网络权限
如:方法封装(返回返回当前连接的wifi的名字)
private String getConnectWifiSsid(){
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMa