今天用魅族手机测试,发现wifi名为"wifi",其它手机不是这样,比如:小米、三星、oppo。
经过调试发现,魅族手机WifiInfo信息如下:
wifiInfo =SSID: wifi, BSSID: 00:00:00:00:00:00, MAC: 00:00:00:00:00:00, Supplicant state: COMPLETED, RSSI: -1, CHANNEL:0, Link speed: 1000, Net ID: 1, Metered hint: false
其它牌子的手机WifiInfo信息如下:
wifiInfo =SSID: WOAOTPO, BSSID: 14:75:90:c8:d3:44, MAC: 02:00:00:00:00:00, Supplicant state: COMPLETED, RSSI: -30, Link speed: 144Mbps, Frequency: 2437MHz, Net ID: 8, Metered hint: false, score: 0
我们可以很明显发现魅族手机的BSSID和MAC全为零,我很想知道可不可以通过"00:00:00:00:00:00".equals(wifiInfo.getBSSID())来判断wifiInfo.getSSID()的值不正常?
当然我找到了一个可以暂时解决的办法,如下:
WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if ( wifiManager.isWifiEnabled() ) {
ConnectivityManager connManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if ( WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()) == NetworkInfo.DetailedState.CONNECTED
|| mWifi.isConnected())
{
String _connectedSsid = wifiInfo.getSSID();
int iLen = _connectedSsid.length();
if (iLen == 0) {
errMsg = getStringForFrag(R.string.tips_wifi_not_connect);
return false;
}
if ( _connectedSsid.startsWith("\"") && _connectedSsid.endsWith("\"") ) {
_connectedSsid = _connectedSsid.substring(1, iLen - 1);
}
if("wifi".equals(_connectedSsid)){
String anotherWifi=mWifi.getExtraInfo();
if(anotherWifi==null){
mWifiName = _connectedSsid;
}else {
if(anotherWifi.startsWith("\"") && anotherWifi.endsWith("\""))
anotherWifi=anotherWifi.substring(1,anotherWifi.length()-1);
mWifiName=anotherWifi;
}
}else {
mWifiName = _connectedSsid;
}
}else{
errMsg = getStringForFrag(R.string.tips_wifi_not_connect);
return false;
}
}
经过调试发现,魅族手机WifiInfo信息如下:
wifiInfo =SSID: wifi, BSSID: 00:00:00:00:00:00, MAC: 00:00:00:00:00:00, Supplicant state: COMPLETED, RSSI: -1, CHANNEL:0, Link speed: 1000, Net ID: 1, Metered hint: false
其它牌子的手机WifiInfo信息如下:
wifiInfo =SSID: WOAOTPO, BSSID: 14:75:90:c8:d3:44, MAC: 02:00:00:00:00:00, Supplicant state: COMPLETED, RSSI: -30, Link speed: 144Mbps, Frequency: 2437MHz, Net ID: 8, Metered hint: false, score: 0
我们可以很明显发现魅族手机的BSSID和MAC全为零,我很想知道可不可以通过"00:00:00:00:00:00".equals(wifiInfo.getBSSID())来判断wifiInfo.getSSID()的值不正常?
当然我找到了一个可以暂时解决的办法,如下:
WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if ( wifiManager.isWifiEnabled() ) {
ConnectivityManager connManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if ( WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()) == NetworkInfo.DetailedState.CONNECTED
|| mWifi.isConnected())
{
String _connectedSsid = wifiInfo.getSSID();
int iLen = _connectedSsid.length();
if (iLen == 0) {
errMsg = getStringForFrag(R.string.tips_wifi_not_connect);
return false;
}
if ( _connectedSsid.startsWith("\"") && _connectedSsid.endsWith("\"") ) {
_connectedSsid = _connectedSsid.substring(1, iLen - 1);
}
if("wifi".equals(_connectedSsid)){
String anotherWifi=mWifi.getExtraInfo();
if(anotherWifi==null){
mWifiName = _connectedSsid;
}else {
if(anotherWifi.startsWith("\"") && anotherWifi.endsWith("\""))
anotherWifi=anotherWifi.substring(1,anotherWifi.length()-1);
mWifiName=anotherWifi;
}
}else {
mWifiName = _connectedSsid;
}
}else{
errMsg = getStringForFrag(R.string.tips_wifi_not_connect);
return false;
}
}