osama-raddad
1/7/2016 - 1:50 PM

Network Info

Network Info


public class Network {
  
	public static DhcpInfo getNetworkInfo(Context context) {
		ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		android.net.NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
		switch (activeNetworkInfo.getType()) {
			case ConnectivityManager.TYPE_ETHERNET:
				return null;
			case ConnectivityManager.TYPE_WIFI:
				WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
				return wifi.getDhcpInfo();
			default:
				return null;
		}
	}
}