Code example for WifiInfo

Methods: getBSSID, getIpAddress, getLinkSpeed, getMacAddress, getNetworkId, getRssi, getSSID

0
		 
		WifiManager wifiMan = (WifiManager) getSystemService(Context.WIFI_SERVICE);
		WifiInfo wifiInfo = wifiMan.getConnectionInfo();
		 
		sb.append("SSID = " + getSSIDSafe(wifiInfo) + "\n");
		sb.append("BSSID = " + wifiInfo.getBSSID() + "\n");
		sb.append("IP Address = " + getWiFiIp(wifiInfo) + "\n");
		sb.append("Network ID = " + wifiInfo.getNetworkId() + "\n");
		sb.append("Rssi(Signal Strength) = " + wifiInfo.getRssi() + "\n");
		sb.append("Link Speed(Mbps) = " + wifiInfo.getLinkSpeed() + "\n");
		sb.append("WiFi MAC = " + wifiInfo.getMacAddress() + "\n");
		 
		TelephonyManager telMan = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
		 
		sb.append("\n\n");
		sb.append("3G Information\n");
		sb.append("Connection Type: " + telMan.getNetworkType() + "\n");
		sb.append("Country: " + telMan.getNetworkCountryIso().toUpperCase() + "\n");
		sb.append("Network Name: " + telMan.getNetworkOperatorName() + "\n");
		sb.append("3G Data State: " + telMan.getDataState() + "\n");
		 
		wifiInformationString = sb.toString();
		 
		return sb.toString();
	} 
	 
	private String pingGoogle(){
		NetworkAccess net = new NetworkAccess();
		try{ 
			String ret = net.executeHttpGet();
			if(ret.equalsIgnoreCase("SocketException")){
				return ret;
			}else if(ret.equalsIgnoreCase("")){
				return "Unknown Exception. See Log"; 
			} else { 
				return "Pinging Google: Sucessfully received a response from Google."; 
			} 
			 
		} catch (Exception ex){
			Log.d("NetworkConnectivity", "Error: " + ex);
			return "There was an exception of type: " + ex.getLocalizedMessage();
		} 
	} 
 
	private String getWiFiIp(WifiInfo wifiInfo) {
		int ipAddress = wifiInfo.getIpAddress();
		 
		return String.format("%d.%d.%d.%d", (ipAddress & 0xff), 
											(ipAddress >> 8 & 0xff),
											(ipAddress >> 16 & 0xff),
											(ipAddress >> 24 & 0xff));
	} 
 
	private String getSSIDSafe(WifiInfo wifiInfo){
		try{ 
			return wifiInfo.getSSID();
		}catch (Exception e){
			return null; 
		} 
	}