Reputation: 393
i want to get some information about Wifi like SSID Name, ip address and speed, so i wrote this code
WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
int speed = wifiInfo.getLinkSpeed();
speedString = Integer.toString(speed);
mac = wifiInfo.getMacAddress();
ssid = wifiInfo.getSSID();
ipAddress = Formatter.formatIpAddress(ip);
The problem is that if the WiFi is enabled but the phone is not connected to any network i show
SSID: 0x
Ip: 0.0.0.0
Speed: -1 mbps
I do not want to display this type of information so I tried it with
if(ipAddress=="0.0.0.0") {
Ip.setSummary("Not connected");
}
But don't work because i see the same information (ssid: 0x, ip: 0.0.0.0 ecc). How can i fix?
Upvotes: 0
Views: 1969
Reputation: 9152
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
int speed = wifiInfo.getLinkSpeed();
speedString = Integer.toString(speed);
mac = wifiInfo.getMacAddress();
ssid = wifiInfo.getSSID();
ipAddress = Formatter.formatIpAddress(ip);
}
Try this
Upvotes: 1